Repository navigation
Fall back from SRQ to a dedicated RQ before TCP - #3782
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A critical RDMA initialization issue remains: eager preallocation of the default resource pool can exhaust HCA or system resources and cause startup failure before the SRQ path can operate.
1 open issue
What changed in this PR
This PR updates RDMA connection negotiation so SRQ-preferring clients can fall back to a dedicated receive queue before using TCP, while adding runtime SRQ admission control and broader compatibility coverage.
Changes:
- Adds client-side dedicated-RQ retry, bounded reconnects, v2/v3 handshake compatibility, deadline handling, and TCP fallback.
- Adds
rdma_connect_srqandrdma_accept_srqflags with cached SRQ capability validation and server admission control. - Expands SRQ/RDMA resource and handshake tests and updates English and Chinese documentation.
| File | Description |
|---|---|
| test/brpc_srq_unittest.cpp | Updates SRQ option and device tests and adds worker recovery and admission-control coverage. |
| test/brpc_rdma_unittest.cpp | Adds handshake fallback, refusal, deadline, queue-mode, and resource-failure tests. |
| src/brpc/rdma/srq_worker.h | Exposes SRQ device capability validation and removes the obsolete SRQ flag declaration. |
| src/brpc/rdma/srq_worker.cpp | Refactors SRQ capability validation and rate-limits resource allocation diagnostics. |
| src/brpc/rdma/srq_receive_pool.cpp | Rate-limits receive-pool allocation and registration errors. |
| src/brpc/rdma/rq_connection.cpp | Enables dedicated-QP resource precreation regardless of SRQ preference. |
| src/brpc/rdma/rdma_helper.h | Declares the SRQ availability query interface. |
| src/brpc/rdma/rdma_helper.cpp | Caches and exposes SRQ hardware and configuration availability. |
| src/brpc/rdma/rdma_handshake.proto | Adds the optional v3 refusal indicator. |
| src/brpc/rdma/rdma_handshake.h | Adds the declined handshake result and updates refusal semantics. |
| src/brpc/rdma/rdma_handshake.cpp | Recognizes explicit and legacy v3 refusals during client negotiation. |
| src/brpc/rdma/rdma_handshake_server.h | Declares shared v3 refusal-message construction. |
| src/brpc/rdma/rdma_handshake_server.cpp | Emits explicit refusal responses for RDMA and TCP-only paths. |
| src/brpc/rdma/rdma_endpoint.h | Declares client negotiation, queue allocation, and handshake-finalization helpers. |
| src/brpc/rdma/rdma_endpoint.cpp | Implements SRQ/private-RQ negotiation, reconnect fallback, server admission, and deadline-aware handshake completion. |
| docs/en/rdma.md | Documents the new SRQ flags, fallback behavior, and resource implications in English. |
| docs/cn/rdma.md | Documents the new SRQ flags, fallback behavior, and resource implications in Chinese. |
Review effort: Lite
|
What specific requirements drove the implementation of backward compatibility for RDMA versions 2 and 3? Maintaining such compatibility adds significant complexity to the codebase. Alternatively, one could handle this via configuration; as time passes and users upgrade their systems, everyone would eventually converge on version 3. |
a03ab83 to
38059de
Compare
@yanglimingcn Automatic v3-to-v2 fallback was introduced in #3745. This PR adds a fallback from SRQ to a dedicated RQ so that a client can continue using RDMA when a server declines SRQ. Both changes support independent rollouts in mixed deployments. Clients and servers are often managed by different teams, so requiring every server team to finish upgrading before a client team can enable a feature can be a significant coordination cost. With per-connection negotiation, a client can use SRQ with servers that accept it and a dedicated RQ with those that do not. A server team can also roll back a version or disable SRQ without asking client teams to change their configuration. Explicit configuration works when one team controls the rollout order. Automatic fallback gives teams the freedom to upgrade and roll back on their own schedules. |
|
LGTM |

What problem does this PR solve?
Issue Number: resolve
Problem Summary:
A client that requests a shared receive queue (SRQ) can fall back to TCP even when both peers support RDMA with a dedicated receive queue (RQ).
What is changed and the side effects?
Changed:
ACK=0and allocates a dedicated QP. It reconnects only if allocation succeeds. Otherwise, it can send the pending RPC over the original TCP connection.qp_num=0and valid dedicated-RQ parameters. Peers that only support v2 can still negotiate a dedicated RQ. Each logical connection gets at most two hello exchanges under the original connect deadline. A scheduling delay after the final ACK no longer turns a completed handshake into a timeout.rdma_connect_srqfor outgoing connections (defaultfalse) andrdma_accept_srqfor incoming connections (defaulttrue). Turning off server admission through/flagsdeclines new SRQ requests before allocating resources. Established SRQ connections continue serving RPCs.Handshake fallback:
Ais the original TCP connection.Bis opened only for a second handshake. Before sending any hello, the client can switch from SRQ to a dedicated RQ onA. If neither QP can be allocated and the connection is still usable, the RPC goes directly over TCP onA.sequenceDiagram participant C as Client participant S as Server C->>S: A · v3 hello with SRQ or dedicated RQ alt Matching queue mode and local QP activation succeeds S-->>C: A · matching RDMA parameters C->>S: A · ACK=1 C->>S: RPC over RDMA else Retryable SRQ failure S-->>C: A · v3 reply C->>S: A · ACK=0 C->>C: Allocate a dedicated QP while A is still usable alt QP allocated C->>S: Open B C->>S: B · v3 hello with dedicated RQ else QP unavailable C->>S: RPC over TCP on A end else Peer closes early, resets, or replies with v2 magic C->>S: Open B C->>C: Reuse or allocate a dedicated QP alt QP ready C->>S: B · v2 hello with dedicated RQ else QP unavailable C->>S: RPC over TCP on B end else Other complete but unusable reply S-->>C: A · unusable RDMA parameters C->>S: A · ACK=0 C->>S: RPC over TCP on A end opt A second hello was sent on B alt Matching parameters and local QP activation succeeds S-->>C: B · dedicated RQ parameters C->>S: B · ACK=1 C->>S: RPC over RDMA else Complete reply but RDMA cannot be established S-->>C: B · hello reply C->>S: B · ACK=0 C->>S: RPC over TCP on B else Another version retry is requested C->>C: Fail the connection end endA retryable SRQ failure is an explicit or historical refusal, a valid dedicated-RQ reply to an SRQ offer, or a local SRQ QP activation failure. A legacy all-zero refusal gives no indication whether the server supports a dedicated RQ. Cancellation, deadline expiry during negotiation, a failed reconnect, or a fatal I/O or framing error ends the handshake with an error.
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: