Repository navigation
Conversation
Signed-off-by: chenjr97 <chenjr97@mail2.sysu.edu.cn>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
0oshowero0
left a comment
There was a problem hiding this comment.
Thanks for the clean optimization and thorough benchmarks! Packing non-tensor payloads directly into pre-registered BufferPool memory avoids both the extra staging copy and dynamic registration, and removing the nested packing thread pool clearly eliminates GIL contention and tail latency. The tests (verifying zero-copy destinations via pack_into and view cleanup on failure) are also very solid.
A few minor suggestions and one design question:
-
Update
use_put_buffer_poolcomments/docs to reflect non-tensor coveragetransfer_queue/config.yaml(L71) andscripts/performance_test/perftest_config.yaml(L55) still state thatuse_put_buffer_poolonly applies to CPU-backed tensor PUTs:
# Reuse the pre-registered buffer pool for CPU-backed tensor PUTs over RDMA.- Since it now covers both CPU-backed tensor and non-tensor PUTs (and the Mooncake
#4491caveat applies to both), please update those config comments, along with the fallback warning atmooncake_client.py:244and the test module docstring attests/test_mooncake_buffer_pool.py:15.
-
Empty-batch guard and scoping
_aligned_offsets(mooncake_client.py:451-482)- Although public
put()never dispatches an empty non-tensor chunk, calling_put_bytes_thread_worker([], [])directly leavesitemsunbound and raisesUnboundLocalErroratdel batch_items, items(and calls_acquire_buffer(0)on the pooled path), whereas_put_tensors_thread_worker([], [])returns cleanly. Adding an earlyif not batch_values: return []prevents that. - Moving
_aligned_offsets(batch_sizes)insideif self.use_put_buffer_pool and self._buffer_pool is not None:also keeps the default (use_put_buffer_pool=False) and TCP paths from doing unnecessary offset calculation.
- Although public
-
Factor out the duplicated
lease.release()error-handling block (mooncake_client.py)- The cause-preserving
try / except Exception: try: lease.release() ... raise; lease.release()boilerplate now appears in 3 places (_write_via_buffer_pool,_put_bytes_thread_worker, and_read_via_buffer_pool). - Since we're touching this path anyway, it would be nice to extract a small internal context manager (e.g.,
_leased_buffer(lease, role)) so this invariant lives in one place.
- The cause-preserving
-
Minor nits (non-blocking)
- Tests: Consider adding a non-tensor value to
TestPutBufferPoolGuards.test_opt_out_registers_put_and_still_pools_getto guard theuse_put_buffer_pool=Falsecontract for non-tensors, and assertingstore.unregistered == [ptrs[0]](plus aget()roundtrip) intest_put_bytes_over_one_share_registers_the_whole_batch_once. - Source views on
pack_intofailure (serial_utils.py:583):del batch_items, itemsnicely ensures source views are released on transport errors. Ifpack_intoitself raises (e.g., target buffer too small orstruct.erroron a >4 GiB item),target_mvis released by thewithblock, butitem_mvsremains referenced by the traceback frame. Releasingitem_mvsin atry/finallywould make cleanup symmetric.
- Tests: Consider adding a non-tensor value to
-
Design choice (up to you / non-blocking): whole-batch fallback above
_pool_share_bytes- With the default
local_buffer_size=1 GiB,_pool_share_bytesis128 MiB. Unlike_put_tensors_thread_worker(which usessplit_by_bytes), any 400-key non-tensor sub-batch exceeding128 MiB(e.g., 400 × 350 KiB, or one 130 MiB value mixed with small values) silently falls back toregister_bufferfor the entire batch without hitting_acquire_buffer(so nothing is logged). - Either choice makes sense—leaving it up to you:
- Keep whole-batch all-or-nothing (simplest code, preserves key order, single RPC, and fallback is still a single registration); in that case, a
logger.debugwhen skipping the pool due tototal > self._pool_share_byteswould help observability. - Or switch to in-order greedy chunking (no reordering, so duplicate keys stay safe) if you'd like >128 MiB batches to still use the pool under the default 1 GiB
local_buffer_size.
- Keep whole-batch all-or-nothing (simplest code, preserves key order, single RPC, and fallback is still a single registration); in that case, a
- With the default
|
#252 I just support the last piece of buffer pool for non-tensor get. We plan to release the next version in next week, hope we can meet the ddl~ |
|
Thanks for the review! We've finished the implementation. We're doing some final cleanup and will publish the update shortly. |
Overview
Extends Mooncake's pre-registered
BufferPooloptimization (#216) to non-tensor RDMA PUTs (MooncakeStoreClient._put_bytes_thread_worker) with two changes:BufferPoolmemory (behinduse_put_buffer_pool, defaultfalse), replacing per-batch allocation andregister_buffer/unregister_bufferwith zero extra staging copy.MAX_SERIAL_WORKER_THREADS) so each outer worker packs its sub-batch inline.Across the 22 reported payload/batch shapes on the launcher with one HCA, the full change delivers 1.185×–4.951× end-to-end PUT speedup over
main, measured at P50.Detail
1. Direct pack into pre-registered
BufferPooluse_put_buffer_poolonly covered CPU-backed tensors. Non-tensor PUTs allocated a fresh contiguousuint8buffer per sub-batch (allocate_empty_tensors), packed into it, and ranregister_buffer→batch_upsert_from→unregister_buffer.use_put_buffer_pool=Trueand the aligned sub-batch fits within_pool_share_bytes,_put_bytes_thread_workerleases a pre-registered slice via_acquire_buffer, packs items directly intomemoryview(lease.buffer)usingserial_utils.pack_into, and calls_batch_upsert_with_retryfrom[lease.ptr + off](0 dynamic registrations).memoryviews inpack_intoand_put_bytes_thread_workerarewith-scoped,batch_itemsare dropped before upsert so source views are not kept alive across errors, and the lease is always released on success or exception.2. Remove inner packing thread pool (
MAX_SERIAL_WORKER_THREADS)MAX_BATCH_WORKER_THREADS = 4, 400 keys/sub-batch) created a nestedThreadPoolExecutor(4)insidebatch_encode_into, spawning up to 16 Python threads contending on the GIL plus per-sub-batch executor and task overhead.MAX_SERIAL_WORKER_THREADSand inlined sequentialpack_intoon each outer batch worker (for both pooled and fallback paths), keeping outer sub-batch parallelism intact.Eval
Setup
main):use_put_buffer_pool=False, nested innerThreadPoolExecutor(4), per-sub-batch register/unregister.use_put_buffer_pool=True, direct pack intoBufferPoolwith innerThreadPoolExecutor(4).use_put_buffer_pool=True, direct pack intoBufferPoolinline on outer workers (no inner thread pool).0.3.12.post1, 1 × 200 Gb/s RDMA HCA (MC_STORE_MEMCPY=0,use_gdr=False), colocated client/controller/storage;local_buffer_size=80 GiB(10 GiB/worker share),global_segment_size=32 GiB,BATCH_SIZE_LIMIT=400,MAX_BATCH_WORKER_THREADS=4.await client.async_put(..., metadata=None)per batch. Each PUT used fresh randombytes. For each of the 22 reported shapes, each variant ran 5 warmups followed by 10 measured PUTs. Payload generation, full readback and partition cleanup were outside the timed call.Results on the launcher (1 HCA)
The table covers 22 shapes with at most 1,600 keys per PUT (up to four 400-key sub-batches). Each latency cell reports P50 / max in milliseconds from the same 10 measured PUTs. Speedups use unrounded P50 latencies. A/B measures direct pool packing, B/C measures the effect of removing the inner pool, and A/C measures the full change. A ratio above 1 means the denominator variant was faster.
Analysis
BufferPoolmemory eliminates per-batchregister_buffer/unregister_bufferoverhead without any additional cost.4 MiB–1 GiB: 0.894×–1.030×, with overlapping 10-run latency ranges on32 MiB × 256and1 GiB × 4), while severely aggravating GIL contention on non-tensor small packets—removing it speeds up all1–256 KiBshapes (1.084×–1.295× at256 KiB, 1.437×–1.514× at1–16 KiB≤400 keys, and 2.122×–3.047× at800–1,600keys).