Repository navigation
[TransferEngine] Add an optional coro_rpc P2P handshake - #5085
Open
staryxchen wants to merge 5 commits into
Open
staryxchen wants to merge 5 commits into
staryxchen wants to merge 5 commits into
Conversation
staryxchen
requested review from
ShangmingCai,
UNIDY2002,
alogfans,
chestnut-Q,
doujiang24,
stmatengss and
ykwd
as code owners
October 30, 2026 04:02
staryxchen
marked this pull request as draft
October 30, 2026 06:03
staryxchen
marked this pull request as ready for review
October 30, 2026 08:25
UNIDY2002
reviewed
Oct 30, 2026
UNIDY2002
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! We tested the coro-based P2P handshake with Mooncake PG, including normal and failure recovery paths. It works as expected and appears compatible with PG.
Collaborator
Author
Thanks for the feedback. After this lands, we would like PG to switch to the coro handshake. It is the more robust: a slow callback no longer blocks every other handshake on the accept thread. |
openSegment can return no descriptor when the peer is down. Sorting that null descriptor crashed the initiator. Signed-off-by: staryxchen <staryxchen@tencent.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Socket stays the default framing. Set MC_HANDSHAKE_TRANSPORT=coro on both peers to serve Connection, Metadata, Notify, and Probe with coro_rpc. The server bounds frame size, in-flight bytes, and per-peer connections, and an unresolved host returns ERR_DNS like the socket plugin. Connection and Metadata callbacks run on a dedicated pool of 2 threads. Signed-off-by: staryxchen <staryxchen@tencent.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The PR format check rewrapped several assertions in coro_handshake_test.cpp. Signed-off-by: staryxchen <staryxchen@tencent.com> Co-authored-by: Cursor <cursoragent@cursor.com>
hipify compiles copies of the .cpp files from the build tree. The sibling headers stay in the source tree, so that directory is now on the include path. Signed-off-by: staryxchen <staryxchen@tencent.com> Co-authored-by: Cursor <cursoragent@cursor.com>
The upgraded ylt checks a response header before allocating, and can refuse a socket before constructing a connection. The handshake client sets both limits to MC_HANDSHAKE_MAX_LENGTH. The server closes a new socket once MC_HANDSHAKE_MAX_CONNECTIONS live connections are open. Signed-off-by: staryxchen <staryxchen@tencent.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In P2P mode, QP handshake, segment metadata, notify, and probe all enter the same handshake daemon.
SocketHandShakePluginserves each accepted connection on the accept thread: it reads the request, runs the callback, writes the reply, and waits for the peer to close. One stuck connection holds every handshake behind it. Once the listen backlog is full, newconnect()calls time out.#5051 hit this in a disaggregated prefill/decode deployment. A rank's handshake listener stopped serving. Peers first saw 5 s read timeouts, then
connect()returnedETIMEDOUTafter the backlog filled. Every transfer that needed a new connection to that rank failed until the process was restarted. The callback that blocked was an EFA passive handshake waiting on its endpoint lock. The same accept thread stalls in the same way for any of these:SO_RCVTIMEO(5 s). Port scans and health checks do this.SO_RCVTIMEOon each read.readFully()checks its 300 s budget only between reads.std::terminate. jsoncpp throws when a field has the wrong JSON type, for example a notify whose"name"is an object. #1369 reported aJson::LogicErrorfrom this thread.#4451 bounded the reply write with
SO_SNDTIMEO. The serial accept loop is still there. #5051 keeps the handwritten server: the accept thread only callsaccept, each connection gets a short-lived thread, and the daemon adds a connection cap and a 5 s read deadline. That still means maintaining the framing, the timeouts, and the thread lifetime. A fixed worker pool of 8 still stalls later handshakes when those 8 connections are slow.This PR adds coro_rpc, which TENT already uses as its control plane, as an optional handshake. The default stays the existing socket server:
MC_HANDSHAKE_MAX_ACTIVE_PER_PEER,MC_HANDSHAKE_MAX_IDLE_PER_PEER). A further call fails immediately withERR_TOO_MANY_REQUESTS. An idle connection is closed on return once the peer is already at the idle cap. A sweep about once a second drops connections that have been idle forMC_HANDSHAKE_IDLE_TTL_SECONDS(default 60), including peers that are never contacted again.ERR_DNS, the same code as the socket plugin. A refused connect staysERR_SOCKET.socket, the length-prefixed JSON server.MC_HANDSHAKE_TRANSPORT=coroselects coro_rpc. Both peers must set the same value. An unset value keeps the framing already deployed, so a rolling upgrade does not mix the two protocols.mooncake-transfer-engine/src/coro_handshake/.include/handshake_rpc.honly exposes the factory functions.This PR does not take these parts of #5051: refusing connections past a cap right after accept, a
poll-based deadline that requires the whole read to finish within 5 s, or that PR's silent-connection, dribbling-byte, and malformed-request tests. The coro read timeout is a total budget for one request, 60 s by default (MC_HANDSHAKE_RPC_TIMEOUT_SECONDS), not a 5 s timer that resets per byte.tebenchreturns an error whenopenSegmentyields no descriptor, instead of dereferencing it.handshake_perfcompares cold, warm, and concurrent latency. It is not a unit test. The change is about 2500 lines and has no separate RFC.Suggested Merge Priority
Module
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
How Has This Been Tested?
Built with
-DWITH_STORE=OFF -DUSE_CUDA=OFF -DUSE_ETCD=OFFagainst stock yalantinglibs7801bc9. The numbers below are from the current tree after rebasing ontoorigin/main(522b716e). Loopback only. No RDMA run and no multi-node run.Test commands:
Test results:
coro_handshake_test: 23 passed.transfer_metadata_test: 23 passed with the default socket transport and 23 passed withMC_HANDSHAKE_TRANSPORT=coro. The etcdTransferMetadataTestfixture was not run because this build hasUSE_ETCD=OFF.tebenchagainst a missing target (127.0.0.1:1) exits 1 instead of segfaulting.tebench, loopback TCP, classic backend, P2P metadata,MC_FORCE_TCP=1,--check_consistency=true, 2 seconds per case. Both transports exited 0. Runs alternate socket then coro. 64KB at 1 thread moves around between runs; the two transports overlap.Handshake is a one-time cost here. After the segment is open, both sides use the same TCP data path. During these runs the coro target stayed at 9 threads. An earlier build posted Connection and Metadata callbacks to ylt's default blocking pool and the target grew to about 391 threads, one per CPU. That pool is no longer used.
handshake_perf, loopback, one run, zero failures. The socket plugin has no connection pool, so its cold and warm rows both open a new TCP connection per call. Cold is 100 calls. Warm is 1000 calls.Cold (a new client each call):
A cold coro call builds a
coro_rpc_clientand opens a framed RPC connection. The socket path is oneconnectplus one write and one read. The Connection p99 of 491 µs is the cost of opening that first coro connection. An earlier cold Connection p99 of about 25 ms came from the first use of a process-wide executor sized to the CPU count. The client now uses a 2-thread pool, and that tail is gone.Warm (one client):
Notify and Probe run on the IO thread and reuse a pooled connection, so they beat the socket path. Connection and Metadata are posted onto the handshake server's 2-thread pool. That hop is what keeps them a little above Notify and Probe, and a little above the socket path. The hop is there so a long RDMA handshake does not block reads on that connection.
Concurrent Probe (200 calls per worker):
One pooled connection carries one in-flight RPC, so a slow Connection cannot head-of-line block a Probe. These concurrent numbers sit in the same band as the previous three-run median (32 workers, coro p99 about 300 µs, about 140k calls/s). An idle cap of 2 closed the extra connections after each burst and pushed that p99 to about 16 ms. The cap is now 128. The socket server still handles one new TCP connection at a time on its accept thread.
Checklist
./scripts/code_format.shAI Assistance Disclosure
Cursor wrote the coro handshake server, the tests,
handshake_perf, and the docs update, and ran the local tests. The human submitter needs to review and defend every changed line.