Skip to content

fix(cn): serve concurrent PRPC requests on one connection - #1739

Draft
aocsa wants to merge 1 commit into
sirius-db:devfrom
aocsa:codex/cn-concurrent-prpc
Draft

fix(cn): serve concurrent PRPC requests on one connection#1739
aocsa wants to merge 1 commit into
sirius-db:devfrom
aocsa:codex/cn-concurrent-prpc

Conversation

@aocsa

@aocsa aocsa commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Serve PRPC requests received on one TCP connection concurrently. The server now splits the socket, clones its Tower service per request, and serializes only response writes. Responses may therefore arrive in completion order while their correlation ids continue to pair them with requests.

This prevents a long fetch_data poll or blocking exec_plan_fragment from holding a later cancel_plan_fragment behind it on the FE's multiplexed CN connection. The included regression test sends a slow fetch_data and a fast cancel_plan_fragment on one connection and proves that the fast response arrives first.

Scope and prerequisites

This is one self-contained file and one preserved source commit. It does not require the peer PRPC client to compile or test. The motivating FE-to-CN exchange/cancellation path still needs the checked-in exchange RPC interface from #1707 (or its landed equivalent) and the later distributed CN runtime; this change is the server-side concurrency primitive that path uses.

Validation

  • pixi run cargo fmt --manifest-path experimental/starrocks/Cargo.toml --check
  • Verified the extracted commit's stable patch-id exactly matches source commit 5e71059c.
  • git diff --check upstream/dev...HEAD

The Cargo test suite was not run: this standalone clone intentionally does not initialize the StarRocks submodule, and the extraction does not warrant a GPU build or rebuild.

The FE multiplexes every RPC to a CN over one brpc connection, pairing responses with requests by
correlation id, but the CN served a connection's requests strictly in line: read a frame, run the
handler to completion, write the response, read the next. A fetch_data long-poll (or a blocking
exec_plan_fragment) therefore held every request queued behind it -- including the
cancel_plan_fragment the FE sends when the CN reports a fragment failure. MEASURED 2026-09-05 on
TPC-H q18 at 2 CNs (arm W2b-2cn): the CN reported the failure at 02:46:07.569, the FE logged
updateStatus -> cancelInternal at once, then eight RpcTimerTask timeouts on its one channel to that
CN, and getNext only saw CANCELLED at 02:50:22 when the query timed out. The client waited 4 min
20 s for a failure the CN had reported in 2 ms.

handle_connection now splits the socket, spawns one task per request (the Tower service is
cloned per request, as it already was per connection), and writes responses in completion order
under a writer lock. Per-sender frame order over the exchange is unaffected: a peer awaits each
transmit_packed reply before sending the next frame of a drain. A test drives a slow and a fast
request down one connection and reads the fast answer first.
@aocsa aocsa added starrocks rust Pull requests that update rust code perf Performance related work labels Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf Performance related work rust Pull requests that update rust code starrocks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant