mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[PR #1084] [MERGED] feat[Store]: Add standalone deployment implementation for Client #2003
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#2003
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/Mooncake/pull/1084
Author: @YiXR
Created: 11/20/2025
Status: ✅ Merged
Merged: 11/25/2025
Merged by: @stmatengss
Base:
main← Head:split-client📝 Commits (6)
d8b7569[Store]: Add independent deployment implementation for Client757d212[Doc]: mooncake-store: add introduce for client standalone mode751d62b[CI]: Add dummy client test54784f7[Store]: Change dummy client setup into a new func8f3ff99[Store]: Add more log for dummy cliente914a78Merge remote-tracking branch 'upstream/main'📊 Changes
28 files changed (+2147 additions, -229 deletions)
View changed files
📝
doc/en/mooncake-store.md(+34 -4)📝
doc/zh/mooncake-store.md(+33 -4)📝
docs/source/design/mooncake-store.md(+34 -4)📝
mooncake-integration/store/store_py.cpp(+121 -24)📝
mooncake-store/include/client_buffer.hpp(+12 -4)📝
mooncake-store/include/client_service.h(+0 -0)➕
mooncake-store/include/dummy_client.h(+185 -0)➕
mooncake-store/include/pyclient.h(+116 -0)📝
mooncake-store/include/real_client.h(+94 -39)📝
mooncake-store/include/utils.h(+93 -0)📝
mooncake-store/src/CMakeLists.txt(+9 -4)📝
mooncake-store/src/client_buffer.cpp(+28 -2)📝
mooncake-store/src/client_service.cpp(+1 -1)➕
mooncake-store/src/dummy_client.cpp(+479 -0)📝
mooncake-store/src/real_client.cpp(+343 -74)➕
mooncake-store/src/real_client_main.cpp(+74 -0)📝
mooncake-store/tests/client_integration_test.cpp(+1 -1)📝
mooncake-store/tests/e2e/client_wrapper.h(+1 -1)📝
mooncake-store/tests/non_ha_reconnect_test.cpp(+1 -1)📝
mooncake-store/tests/pybind_client_test.cpp(+38 -35)...and 8 more files
📄 Description
Description
Thanks @wanyue-wy @stmatengss @XucSh for helping with architectural design.
Type of Change
Architecture Overview
RealClientandDummyClient, ensuring that performance is on par with the non-detached mode.RealClientcontinues to run and provide Storage for the Master even after theDummyClientexits.Code Modification Overview
File Creation/Change Description
client.cpp&client.htoclient_service.cpp&client_service.h.real_client_main.cppas the main process for theRealClient.dummy_client.cpp&dummy_client.hfor theDummyClient.pybind_client.cpp&pybind_client.htoreal_client.cpp&real_client.h. All instances ofclass PyClienthave been renamed toclass RealClient.pyclient.h, which defines a new base classPyClient.PyClientmaintains the interface to ensure backward compatibility. BothRealClient&DummyClientinherit from it and implement the corresponding functions.Key Implementation/Change Details
mooncake-integration/store/store_py.cpp
storeinstore_pyis defined as aPyClientbase class pointer. If the client detached mode is selected, thestoreis instantiated as aDummyClient; otherwise, it's instantiated as aRealClient.mooncake-store/src/dummy_client.cpp
DummyClientImplementation: Implements theDummyClient, which is primarily responsible for connecting to theRealClientand initiating RPC calls. Its high-level interface inherits fromPyClientto remain consistent with the old code.DummyClientis responsible for creating the shared memory. During its setup phase, it creates the shared memory and notifies theRealClienttommapit and register it with the transfer engine.a. The shared memory created by the
DummyClientprovides memory space for the L2 cache (likemem_pool_hostin SGLang) and the client's local buffer (held byclient_buffer_allocator_).b.
shm_size = local_buffer_size + mem_pool_host_size. The first half of the shared memory is used for the L2 cache, and the second half is for the client's local buffer.c. During the
DummyClientsetup phase, theRealClientis notified to register the entire shared memory block with the transfer engine at once. Therefore, there is no need to later callregisterLocalMemoryseparately for the L2 cache.d. After notifying the
RealClienttommapthe shared memory, theDummyClientimmediately callsshm_unlink. This removes the shared memory file, preventing any other external processes from mapping it. Since theRealClienthas already completed themmap, it can continue to access this memory. Due to the kernel's automatic reclamation mechanism for shared memory, the memory will be automatically freed when its reference count drops to zero (i.e., when bothDummyClientandRealClientunmap it).DummyClienthas a Ping thread to maintain its connection with theRealClient.mooncake-store/src/real_client.cpp
RealClientreuses all the implementation from the originalpybind_client(including creating theglobal_segment, holding the transfer engine, communicating with the master, etc.).RealClientregisters its internal functions with an RPC service so they can be called by theDummyClient.a. When notified by the
DummyClientto map the shared memory, theRealClientwillmmapit and record both theDummyClient's side VA (Virtual Address) and its ownRealClientside VA. This facilitates virtual address translation in subsequent zero-copy interface calls.b. The
RealClientuses the second half of the shared memory to create itsclient_buffer_allocator_.RealClient, when handling these functions, must use the previously recorded VAs to perform virtual address translation. This ensures that the virtual addresses it uses are valid in its own context, and the virtual addresses it returns to theDummyClientare valid in theDummyClient's context.RealClientuses a Ping mechanism to continuously monitor the status of theDummyClient. If it detects that theDummyClientis unavailable, it will unmap the corresponding shared memory to ensure timely memory cleanup.mooncake-store/src/client_buffer.cpp
ClientBufferAllocatornow supports being constructed with an external buffer. This change is made to accommodate the requirement of creating aclient_buffer_allocator_using the pre-allocated shared memory.How Has This Been Tested?
To support detached Client mode, the patch described above must be applied to Sglang. (Without the patch, Sglang can still start normally in non-detached mode).
Launching in Detached Mode
a. Start the master:
b. Start the
RealClient(listens on port 50052 by default):c. Start Sglang. Set
MOONCAKE_MASTERto theRealClient's address andMOONCAKE_STANDALONE_STORAGE=1to enable standalone client deployment.Checklist
TODO List
Split Client into DummyClient and RealClient.
Demo for SGLang.
Add CI for DummyClient.
Enable a single
RealClientto serve multipleDummyClients. https://github.com/kvcache-ai/Mooncake/pull/1122Add support for RPC metric collection in
RealClientandDummyClient.Implement a reconnection mechanism for
RealClientandDummyClient. https://github.com/kvcache-ai/Mooncake/pull/1146Introduce a standalone allocator for share mem, enabling Python applications like SGLang to directly allocate shared memory. https://github.com/kvcache-ai/Mooncake/pull/1177
Expand
DummyClientinterface support.a. Currently supported:
putput_batchput_partsremoveremoveByRegexremoveAllisExistbatchIsExistgetSizeget_buffer(replaced byget_buffer_info)batch_put_frombatch_get_intoUnsupported:
batch_get_bufferget_intoput_fromput_from_with_metadatabatch_put_from_multi_buffersbatch_get_into_multi_buffersget_tensorput_tensorbatch_put_tensorbatch_get_tensor🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.