Andrey Yarovoy created RATIS-2787:
-------------------------------------
Summary: spread appendEntries between two servers over more than
one connection
Key: RATIS-2787
URL: https://issues.apache.org/jira/browse/RATIS-2787
Project: Ratis
Issue Type: Improvement
Components: gRPC
Reporter: Andrey Yarovoy
Assignee: Andrey Yarovoy
**Current behaviour** (master, `ratis-grpc`):
- `GrpcServicesImpl` keeps one `GrpcServerProtocolClient` per peer server (a
`PeerProxyMap`), shared by all divisions
on the server.
- `GrpcLogAppender.getClient()` takes it from
`getProxies().getProxy(getFollowerId())`.
- `GrpcServerProtocolClient.appendEntries()` always uses `asyncStub` on the
client's one main `channel`. Heartbeats go
to `hbChannel` when `raft.grpc.server.heartbeat.channel` is true.
- The stub pool from RATIS-2325 (`raft.grpc.server.stub.pool.size`) applies
only to `readIndex`.
So with N groups shared between two servers, all N groups' appendEntries
streams, including their state machine
data, are multiplexed onto one HTTP/2 connection. Netty pins a connection to
one event-loop thread, so all of that
traffic is encrypted, framed and decrypted by one thread at each end.
**Why it matters: Apache Ozone.** An Ozone datanode is one RaftServer hosting
many RATIS/THREE groups (pipelines),
typically 20–40 per datanode. Each `WriteChunk` log entry carries up to 4 MB of
chunk data as state machine data. On
a 12-datanode cluster (80 cores and a 200 Gb/s NIC per node, Ozone 2.2.0, gRPC
TLS 1.3 on), during a large
concurrent 3-way write (TestDFSIO, 1000 × 1 GB, 40 pipelines per datanode):
- **Replication is concentrated on a few connections.** Each datanode moved
3–3.8 GB/s over the Ratis server port, on
about one data connection per peer (plus the heartbeat connection). The busiest
single connections carried
450–770 MB/s one way; others were under 100 MB/s, depending on how many groups
each pair shares.
- **A few event-loop threads carry it.** Of 80 gRPC event-loop threads per
datanode, only 10–19 were busy. The
hottest averaged 43–72% of a core, with 5 s peaks of 78–96%; 79–87% of its CPU
samples (JFR) were TLS record
encryption and decryption (netty-tcnative / OpenSSL). TLS was 25–27% of all
datanode CPU.
- **Nothing else waited.** The request path showed no lock contention or I/O
waits worth mentioning. The writers
meanwhile spent most of their time waiting for commits.
- **Turning TLS off confirms the cost.** With gRPC TLS turned off (everything
else the same), the same write rose from
7.6 to 8.6–8.8 GB/s, and the hottest event loops fell to a median of 37%.
Across the TestDFSIO matrix the fitted 3-way
write rate rose about 20%, while Ozone's erasure-coded writes, which don't
replicate between datanodes, gained only
10–16%.
The mapping from the hot threads to the hot connections wasn't measured
directly; it's inferred from Netty's
one-thread-per-connection model and from the traffic being concentrated on the
peer connections.
**Proposal.** Let appendEntries between two servers use more than one
connection:
- Give `GrpcServerProtocolClient` K appendEntries channels (or reuse the
existing stub pool), and pin each group's
appender to one of them, for example by `groupId` hash. That keeps each group's
stream ordered on one connection
while spreading groups over K connections, and so over up to K event-loop
threads at each end.
- Make K configurable, for example `raft.grpc.server.log-appender.connections`
(or extend
`raft.grpc.server.stub.pool.size` to appendEntries), with default 1 to keep
today's behaviour.
- Heartbeats keep their separate channel.
**Considerations.**
- Ordering is per group (per appender stream), so pinning a group to one
connection doesn't change the semantics.
- More connections per peer cost memory (HTTP/2 flow-control windows, TLS
sessions) and handshakes. K small (2–8) is
likely enough.
- The `too_many_pings` GOAWAY seen when RATIS-2325 was first merged suggests
the keepalive settings need care for
extra channels.
**How to verify.**
- A multi-group benchmark between two servers with TLS on: throughput against
K, and per-thread CPU of the
event-loop group.
- In Ozone: rerun the large 3-way write with K = 1, 2, 4.
Related: RATIS-2325 (GrpcStubPool for readIndex), RATIS-2234 (heartbeat and
appendEntries channels).
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)