Skip to content

[perf] Reuse Mooncake buffer pool for non-tensor RDMA gets - #252

Merged
0oshowero0 merged 2 commits into
Ascend:mainfrom
0oshowero0:perf/mooncake-nontensor-get-buffer-pool
Dec 2, 2026
Merged

0oshowero0 merged 2 commits into
Ascend:mainfrom
0oshowero0:perf/mooncake-nontensor-get-buffer-pool

Conversation

@0oshowero0

@0oshowero0 0oshowero0 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Extend the pre-registered BufferPool receive path introduced for tensors in #175 to non-tensor RDMA reads (MooncakeStoreClient._get_bytes_thread_worker).

Previously, _get_bytes_thread_worker allocated a fresh uint8 region and called register_buffer / unregister_buffer around every 400-key batch, paying repeated kernel page-pinning and multi-HCA MR setup/teardown cost on mixed workloads (e.g., NonTensorStack fields).

Implementation

  • Delegate the raw byte read in MooncakeStoreClient._get_bytes_thread_worker directly to self._get_tensors_thread_worker over 1-D torch.uint8 buffers, then decode via serial_utils.batch_decode_from(batch_buffer_tensors) after the read completes.
  • Document the CPU-resident, caller-owned memory contract on _get_tensors_thread_worker (shared by _get_bytes_thread_worker) and update the missing-BufferPool warning text to cover all CPU reads and puts.
  • Lifetime safety: serial_utils.batch_decode_from returns zero-copy views (torch.frombuffer / np.frombuffer) for tensors and NumPy arrays embedded inside non-tensor values. Because _get_tensors_thread_worker copies from the leased BufferPool slab into caller-owned uint8 tensors and releases the lease before returning, decoded zero-copy views never reference pooled memory, cannot block lease.release() / BufferPool.close(), and survive subsequent buffer reuse.
  • Compatibility & fallback: Automatically inherits split_by_bytes per-worker share bounding, vectorized strided copy-out for uniform sizes, merged direct-registration fallback for oversized payloads or pool exhaustion, and unpooled behavior on TCP or mooncake-transfer-engine builds without BufferPool. No configuration or public API changes.

Evaluation

Setup

Both baseline (ffde754) and candidate (b22fd50, functionally identical to the rebased 304b827 which only adds a docstring and updates the missing-pool warning text) were benchmarked on the same 2-node cluster using scripts/performance_test/perftest.py with the cross-node MooncakeStore placement fix shipped in #251 (296250c, use_inter_node = self.backend == "Yuanrong" or (self.backend == "MooncakeStore" and self.worker_node_ip is not None)):

Setting Value
Topology 2-node cross-node Writer → Reader, 8× 400 Gb/s ConnectX-7 RoCE v2 HCAs per node
Transport protocol: rdma, metadata_server: P2PHANDSHAKE, device: cpu, use_gdr: false
Buffer sizes global_segment_size: 80 GB, local_buffer_size: 80 GB per client (use_put_buffer_pool: true)
Software mooncake-transfer-engine-cuda13==0.3.14, Rust Controller (--controller_backend=rust)
Workload --use_complex_case (1/3 regular tensors, 1/3 jagged nested tensors, 1/3 NonTensorStack strings; 4 iterations per size)

Command (identical for baseline and candidate):

python scripts/performance_test/perftest.py \
  --backend_config=<mooncake_config.yaml> \
  --backend=MooncakeStore \
  --controller_backend=rust \
  --device=cpu \
  --global_batch_size=<1024|4096|8192> \
  --field_num=<9|15|18> \
  --seq_len=<8192|32768|100000> \
  --num_test_iterations=4 \
  --head_node_ip=<HEAD_NODE_IP> \
  --worker_node_ip=<WORKER_NODE_IP> \
  --use_complex_case

Placement log confirmed on both baseline and candidate runs:

INFO - Overriding storage_backend to: MooncakeStore
INFO - Overriding controller.backend to: rust
INFO - Writer is on <HEAD_NODE_IP>, Reader is on <WORKER_NODE_IP>
INFO - Using MooncakeStore as storage backend.

Complex Case GET Performance

Workload (Total Size / Non-Tensor Keys) main Top-3 GET This PR Top-3 GET Top-3 Gain main All-4 GET This PR All-4 GET All-4 Gain
Small (0.23 GB / 3,072 keys) 0.498 s (3.782 Gbps) 0.395 s (4.750 Gbps) -20.7% / +25.6% 0.852 s (3.081 Gbps) 0.427 s (4.459 Gbps) -49.9% / +44.7%
Medium (6.25 GB / 20,480 keys) 5.696 s (8.801 Gbps) 5.492 s (9.111 Gbps) -3.6% / +3.5% 5.876 s (8.549 Gbps) 5.678 s (8.838 Gbps) -3.4% / +3.4%
Large (45.78 GB / 49,152 keys) 28.081 s (13.067 Gbps) 25.414 s (14.412 Gbps) -9.5% / +10.3% 28.671 s (12.808 Gbps) 25.596 s (14.311 Gbps) -10.7% / +11.7%

Top-3 excludes the single slowest GET iteration out of 4; All-4 includes the cold first iteration.

Per-iteration GET latency (seconds):

  • Small: [1.913, 0.453, 0.523, 0.518] → [0.523, 0.392, 0.397, 0.395] (cold iteration cut by 72.7%)
  • Medium: [5.922, 5.297, 6.415, 5.868] → [6.235, 5.528, 5.288, 5.661]
  • Large: [30.441, 29.688, 26.653, 27.903] → [25.865, 25.011, 26.143, 25.367]

Key observations & known workload boundaries:

  • Reader-side dynamic MR registrations during GET dropped from 123 batches × 8 HCAs per Large iteration to 0 across all 3 scales (0 pool fallbacks).
  • On Large, the remaining ~25 s GET latency is dominated by GIL-bound msgspec string decoding (~19.66 GB of strings) and TensorDict assembly rather than RDMA MR registration; eliminating dynamic MR registration still reduces steady-state Large GET latency by ~9.5–10.7% and removes multi-HCA MR registration tail spikes.
  • Equal-length vs. ragged non-tensors: --use_complex_case generates equal-length NonTensorStack strings that hit the vectorized uniform=True copy-out fast path in _copy_between_buffer_and_tensors; real variable-length non-tensors take the per-item ragged copy loop (inherited from [optim] Lease pre-registered receive buffers on the MooncakeStore read path #175).
  • Fragmented partial fallback: When multiple non-adjacent oversized entries (exceeding _pool_share_bytes) or mid-batch pool exhaustion occur in a variable-length batch, split_by_bytes reorders by size so fallback slots can be non-contiguous in the backing buffer, resulting in multiple register_buffer calls rather than one (also shared with ragged tensors in _get_tensors_thread_worker). Both workload boundaries will be tracked as dedicated follow-ups.

Validation

  • Added unit tests in tests/test_mooncake_buffer_pool.py covering:
    • Mixed tensor + non-tensor client.get() with zero register_buffer calls;
    • Non-tensor reads containing strings, bytes, and embedded torch.Tensor / np.ndarray surviving pool arena reuse and client.close();
    • Multi-round split_by_bytes slicing, oversized-item direct-registration fallback, and single-pass fallback on pool exhaustion;
    • TCP and missing-BufferPool fallback paths;
    • Buffer release and exception preservation on transfer failure.
  • Passed python -m compileall -q transfer_queue tutorial tests.
  • Passed pytest -q tests/test_mooncake_buffer_pool.py (38 passed) after rebasing onto main (296250c).
  • Passed pre-commit hooks (ruff, ruff format, mypy, license header check, docstring check).
  • Verified end-to-end on a 2-node 8-HCA RDMA cluster across Complex Small / Medium / Large workloads.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T08:17:28.931661Z b22fd50 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
@0oshowero0
0oshowero0 force-pushed the perf/mooncake-nontensor-get-buffer-pool branch from b22fd50 to 304b827 Compare December 2, 2026 10:47
@0oshowero0
0oshowero0 merged commit d6988ed into Ascend:main Dec 2, 2026
16 checks passed
@0oshowero0
0oshowero0 deleted the perf/mooncake-nontensor-get-buffer-pool branch December 2, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant