Skip to content

[TE] hp_tcp: assign each operation to the least-loaded lane - #4935

Merged
staryxchen merged 2 commits into
kvcache-ai:mainfrom
leoleoasd:fix/hp-tcp-least-loaded-lane
Oct 29, 2026
Merged

staryxchen merged 2 commits into
kvcache-ai:mainfrom
leoleoasd:fix/hp-tcp-least-loaded-lane

Conversation

@leoleoasd

@leoleoasd leoleoasd commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

hp_tcp picked a lane from a per-peer submission sequence (lane_sequence % connections_per_peer), regardless of which lanes were busy. Each lane runs one operation at a time, so under a closed-loop client (a fixed number of transfers in flight, one submitted per completion) the lane that just finished received its next operation only after the sequence came back around, i.e. after connections_per_peer more completions. Lane utilization then settles at whatever fraction it starts at (busy fraction A/N is self-consistent for any number A of active lanes), and with deeper windows the equal round-robin split piles the window onto the slowest connections.

Measured on two VMs over a 200 Gb/s pod network (16 MB writes, host memory, 16 lanes): every lane received a request every ~30 ms and transferred for ~15 ms; 7-9 of 16 lanes were sending at any time; the gap from a lane's response to its next request header was 14-17 ms while the client resubmitted within 0.6 ms. Throughput was 5.6-8.9 GB/s with occasional 14-15 GB/s runs.

Keep an outstanding-operation count per (target, lane) and give each single-slice operation to the lane with the fewest outstanding operations, ties broken from the round-robin position so the original spreading is kept. The count is released on completion and on both cancel paths. Multi-slice (rail-striped) operations are unchanged.

1 pair, 16 lanes: 7.9-9.2 -> 12.9-14.9 GB/s, run-to-run spread < 10%. 1 pair, 48 lanes, 32 workers: 19.8 GB/s. 2 process pairs: 10.9 -> 19.2 GB/s (classic tcp 19.8, iperf3 21.7).

fixes #4934

Description

Suggested Merge Priority

  • P0 — Urgent: Critical security vulnerability, data loss/corruption, or widespread production outage requiring immediate action
  • P1 — High: Significant correctness or stability issue in existing functionality, or a regression blocking users without a practical workaround
  • P2 — Normal: Routine bug fix, validated performance/compatibility improvement, or new feature for a confirmed use case
  • P3 — Low: Experimental feature, optional enhancement, refactoring, or cleanup with no urgent user impact

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test commands:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DWITH_TE=ON -DWITH_STORE=OFF \
  -DUSE_TENT=ON -DUSE_CUDA=OFF -DBUILD_UNIT_TESTS=ON
ninja -C build tent_hp_tcp_buffer_registry_test tent_hp_tcp_e2e_test tent_hp_tcp_protocol_test \
  tent_hp_tcp_socket_test tent_hp_tcp_transport_config_test tent_hp_tcp_transport_test tent_hp_tcp_workers_test
cd build && ctest -R hp_tcp --output-on-failure
 1/9 tent_hp_tcp_transport_config_test ..............   Passed
 2/9 tent_hp_tcp_workers_test .......................   Passed
 3/9 tent_hp_tcp_protocol_test ......................   Passed
 4/9 tent_hp_tcp_buffer_registry_test ...............   Passed
 5/9 tent_hp_tcp_e2e_WriteThenReadAcrossTwoRails ....   Passed
 6/9 tent_hp_tcp_e2e_WriteThenReadConcurrency16 .....   Passed
 7/9 tent_hp_tcp_e2e_UnevenSlicedReadAcrossProcesses    Passed
 8/9 tent_hp_tcp_socket_test ........................   Passed
 9/9 tent_hp_tcp_transport_test .....................   Passed
100% tests passed, 0 tests failed out of 9

Throughput (manual):

  • Two VMs on a VXLAN pod network. iperf3 reaches 173.5 Gb/s (~21.7 GB/s) with 32 streams and 9.7 Gb/s (~1.2 GB/s) with one stream.
  • Host memory, 16 MB WRITEs. Each sender process keeps N writes in flight via transfer_submit_write / transfer_check_status.
  • hp_tcp config: worker_count=16, connections_per_peer=16 unless noted.
  • Unit is GB/s.
Setup Before After Classic tcp (16 lanes)
1 pair, 16 in flight 7.9–9.2 12.9–13.2 13.7
1 pair, 32 in flight 8.7 14.9 —
1 pair, 64 in flight 5.5–8.9 (occasionally 14–15) 12.0–15.7 11.7–14.8
1 pair, 64 in flight, latency p50 / p90 17 / 400–650 ms 66 / 142 ms (≈ 4 × 16.5 ms, balanced) —
1 pair, 48 lanes, 32 workers, 128 in flight — 19.8 — (32 lanes drops to ~4 GB/s)
2 pairs, 32 in flight each 10.9 19.2 19.8

After the fix, the run-to-run spread is under 10% (previously 5.6–15 GB/s for one configuration). Variability improves substantially at 16 in flight; at 64, throughput improves but CV increases from 5.1% to 6.9%.

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

Claude Code helped run experiment and diagnose & drafted the patch.

hp_tcp picked a lane from a per-peer submission sequence
(lane_sequence % connections_per_peer), regardless of which lanes were
busy. Each lane runs one operation at a time, so under a closed-loop
client (a fixed number of transfers in flight, one submitted per
completion) the lane that just finished received its next operation only
after the sequence came back around, i.e. after connections_per_peer more
completions. Lane utilization then settles at whatever fraction it starts
at (busy fraction A/N is self-consistent for any number A of active
lanes), and with deeper windows the equal round-robin split piles the
window onto the slowest connections.

Measured on two VMs over a 200 Gb/s pod network (16 MB writes, host
memory, 16 lanes): every lane received a request every ~30 ms and
transferred for ~15 ms; 7-9 of 16 lanes were sending at any time; the
gap from a lane's response to its next request header was 14-17 ms while
the client resubmitted within 0.6 ms. Throughput was 5.6-8.9 GB/s with
occasional 14-15 GB/s runs.

Keep an outstanding-operation count per (target, lane) and give each
single-slice operation to the lane with the fewest outstanding
operations, ties broken from the round-robin position so the original
spreading is kept. The count is released on completion and on both
cancel paths. Multi-slice (rail-striped) operations are unchanged.

1 pair, 16 lanes: 7.9-9.2 -> 12.9-14.9 GB/s, run-to-run spread < 5%.
1 pair, 48 lanes, 32 workers: 19.8 GB/s. 2 process pairs: 10.9 -> 19.2
GB/s (classic tcp 19.8, iperf3 21.7).
Copilot AI balanced review requested due to automatic review settings October 26, 2026 02:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@staryxchen

Copy link
Copy Markdown
Collaborator

@jacklin78911-collab Could you take a look?

@jacklin78911-collab

Copy link
Copy Markdown
Collaborator

Thanks for the diagnosis. The lane-utilization measurements are consistent with the observed throughput gap, and picking the lane with the fewest outstanding ops is a reasonable minimal fix.

Blocking:

  1. Lane counts can leak. planTask() increments lane_load_, but some planned commands never reach run/cancel/complete:

    • submitTransferTasks(): if planTask() fails for request i, the commands already planned for earlier requests are dropped.
    • tryCommitBatch() can return before posting, e.g. on admission rejection (TooManyRequests, the normal backpressure path), and the commands are destroyed without calling cancel.
    • retryTransferTask(): same pattern when the commit is rejected.
      Each case leaves +1 on a lane permanently, so that lane keeps being avoided. Rolling back the planned increments on these failure paths is enough.
  2. Please add a unit test showing the counts return to zero after an admission rejection and after a mid-batch planTask() failure.

  3. Please post a few repeated after-fix runs for in-flight 16 and 64 separately, so the run-to-run spread can be checked for each.

Follow-ups, not needed for this PR: low-concurrency and P99 numbers, a multi-rail config, and counting striped READ slices.

The per-lane outstanding count was taken when an operation was planned and
given back only on completion or cancellation. Planned commands that never run
leaked it: a batch whose later request fails to plan drops the commands planned
for earlier requests, and tryCommitBatch() can reject (admission backpressure,
TooManyRequests) and destroy the commands without calling cancel; retries have
the same pattern. Each leak left +1 on a lane for good, so the lane was avoided
from then on.

The count is now held by a LaneSlot shared by the planned command, the queued
operation and its completion callback. It is released explicitly on completion
and on both cancel paths (so the next submission sees the lane free at once),
and otherwise when the last holder is destroyed, at most once. Every path that
drops a planned command, current or future, gives the count back.

Test: LaneLoadReturnsToZeroOnRejectedSubmits checks that the counts return to
zero after an admission rejection, after a mid-batch planning failure, and
after a completed transfer. It fails on the previous revision (all three
checks) and passes with this change; ctest -R hp_tcp: 9/9.
@jacklin78911-collab

Copy link
Copy Markdown
Collaborator

Thanks, I reviewed 6e0d15a6. The LaneSlot ownership now covers dropped commands, including rejected retries.

I recompiled the changed transport/header and new regression against cached CPU runtime dependencies. The regression passes on 6e0d15a6 and fails on 5b1b5932, confirming that it catches the original leak. This resolves points 1 and 2 from my earlier review.

I also ran a supplementary native HP_TCP comparison on two-process WSL2 loopback: 16 MiB WRITEs, 16 lanes, 32 GiB cumulative transfers using reused buffers, three fresh-process runs per case. Compared with pre-PR round-robin, median throughput was about 4.5% lower at 16 in flight and essentially unchanged at 64. P50 increased slightly; P99 improved at both depths. A separate comparison before/after the LaneSlot fix showed similar throughput.

These are local diagnostics and do not independently validate the original VM-network throughput claim. The remaining item from my review is the repeated in-flight 16 and 64 results from that environment. I found no further correctness blocker in this revision; current-head CI still needs to complete.

@leoleoasd

Copy link
Copy Markdown
Contributor Author

Thanks. I'm testing it on Nebius uk-south-1 B300s.

Repeated runs (VM network). Same setup as the description: one sender/receiver pair on two VMs over the VXLAN pod network, hp_tcp worker_count=16 / connections_per_peer=16, 16 MB writes, 32 GB per run. Runs of the two builds were interleaved, 10 runs per configuration, all with 0 errors.

build in-flight runs min median max max/min CV
this PR 16 10 11.02 13.20 14.45 1.31× 8.3%
this PR 64 10 11.72 13.66 14.99 1.28× 6.9%
before 16 10 6.09 8.21 14.09 2.31× 28.1%
before 64 10 8.14 8.37 9.25 1.14× 5.1%

Individual runs (GB/s, in run order):

build in-flight runs
this PR 16 13.47, 12.02, 12.12, 12.26, 11.02, 14.45, 13.70, 14.16, 13.38, 13.02
this PR 64 13.30, 11.72, 12.33, 14.17, 13.55, 13.98, 13.78, 13.01, 14.99, 13.79
before 16 8.21, 8.30, 8.32, 8.21, 8.40, 8.22, 6.10, 6.14, 14.09, 6.09
before 64 8.27, 8.17, 8.24, 8.44, 8.14, 9.11, 9.25, 8.30, 9.07, 8.85

@jacklin78911-collab

Copy link
Copy Markdown
Collaborator

Thanks for the repeated runs and individual samples. These address the remaining measurement request, and the current CI Gate is green.

Please update the “run-to-run spread under 5%” statement in the description to reflect these results: the after-fix CVs are 8.3% and 6.9%. Variability improves substantially at 16 in flight; at 64, throughput improves but CV increases from 5.1% to 6.9%.

The earlier accounting and regression-test concerns are resolved, and I have no further code changes to request. LGTM once the description reflects the updated measurements.

@leoleoasd

Copy link
Copy Markdown
Contributor Author

Thanks! I've updated the description

@github-actions github-actions Bot added the size/M 100-1000 changed lines (additions + deletions) label Oct 27, 2026
@leoleoasd

Copy link
Copy Markdown
Contributor Author

@jacklin78911-collab Hi! Thanks for the detailed comment and review. Can you take a look at the updated description?

@jacklin78911-collab

Copy link
Copy Markdown
Collaborator

Thanks, I checked the updated description. LGTM.

@staryxchen staryxchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank @jacklin78911-collab for the detailed review.

@staryxchen
staryxchen merged commit 5805e84 into kvcache-ai:main Oct 29, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci size/M 100-1000 changed lines (additions + deletions) Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TENT hp_tcp is ~40% slower than the classic (non-TENT) TCP transport with the same number of connections

4 participants