mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #2633] [RFC]: Host-aware Local-first Allocation for Mooncake Store #693
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#693
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?
Originally created by @yokinoshitayoki on GitHub (Jun 26, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/2633
Changes proposed
Motivation
Mooncake Store currently supports preferred allocation through
ReplicateConfig.preferred_segmentandReplicateConfig.preferred_segments. When no preferred segment is specified, memory replicas are allocated by the configured allocation strategy, which commonly falls back to a random segment.For KV cache workloads, random placement also increases the failure blast radius of a store node. In the current Mooncake Store cluster, when a store node goes offline, either because of a crash or planned shutdown, all KV cache stored on that node is lost. KV cache reuse depends on a continuous prefix. If a block in the middle of a request's cached sequence is missing, the later cached blocks can no longer be reused even if they still exist on other store nodes. Those suffix blocks remain stored in the cluster but lose their practical value for prefix reuse.
With random placement, KV cache blocks produced by one writer may be spread across many store nodes. A single store node failure can therefore punch holes into cached sequences from many different writers and invalidate the suffixes behind those holes. Host-aware local-first placement reduces this blast radius in the common case by keeping a writer's cache on local store segments first and only using remote hosts when local capacity is insufficient.
Locality is also a motivation. The writer is usually an inference engine process running on a specific physical host. If the KV cache is stored on a remote host while local CPU memory is available, later transfers between the inference engine and Mooncake Store may cross the network unnecessarily. This increases latency and consumes network bandwidth.
The existing preferred segment interface can be used by an upper layer such as vLLM or SGLang, but it requires the upper layer or deployment system to know the exact
Segment.nameof the local store. This is fragile for a general-purpose Mooncake feature:Segment.nameis a logical string and has no required host/IP format.This RFC proposes a host-aware local-first allocation mode inside Mooncake Store. Mooncake master will maintain host-level topology metadata and use it to prefer local store segments for Put allocation. If local segments cannot satisfy the allocation, master will fall back to other hosts in a deterministic ordered sequence rather than choosing a random segment immediately.
Goals
Add a Mooncake-native notion of physical host identity,
host_id.Let master map writer clients to hosts and hosts to active store segments.
Reduce the failure blast radius of one store node by avoiding unnecessary cross-host scattering of one writer's KV cache.
Prefer segments on the writer's host when no explicit preferred segment is provided.
Fall back to remote hosts in a deterministic host-ordered sequence, for example:
Within the same host, rotate the starting segment by key hash so multiple local segments are used more evenly.
Preserve the current explicit
preferred_segment(s)behavior.Keep the first implementation at host granularity. NUMA/GPU-aware placement can be built later on top of the same metadata model.
Non-goals
Segment.name.Current Behavior
Mooncake master currently tracks segment ownership by client and by segment name. The relevant relationships are:
Segment.nameis the logical name used for preferred allocation. A normal memory segment uses the local client'slocal_hostnameasSegment.name.Segment.te_endpointis used for transport addressing. It may contain an IP:port endpoint, but it is not a stable physical host identity. It can be affected by multi-NIC selection, container networking, hostname/IP mismatch, or protocol-specific behavior.When
ReplicateConfig.preferred_segment(s)is set, allocation tries those segments first and then falls back to the existing strategy. When no preferred segment is set, master does not currently infer which segments are local to the writer.Proposed Change
1. Introduce
host_idAdd a new logical field named
host_id.host_idis separate fromlocal_hostname.Example:
2. Resolve
host_idin the Mooncake clientMooncake client should resolve
host_idwithout requiring inference engines to understand Mooncake segment placement.Recommended priority:
Explicit environment variable:
Optional explicit field in Mooncake config or setup options.
Best-effort fallback generated by Mooncake, for example hostname or the existing local host identity.
The best-effort fallback should be documented as a convenience mode, not a strict correctness guarantee. In containerized or multi-NIC environments, operators should set
MOONCAKE_HOST_IDexplicitly.3. Register client host metadata on master
Master needs to know the writer's host even when the writer does not mount a segment. Therefore storing
host_idonly onSegmentis not enough.Master should maintain:
The client should register or refresh its
host_idwhen it connects to master or during the existing client/master setup path. Store clients should also attachhost_idto mounted segments, so the master can rebuild host-to-segment indexes when segments are mounted, remounted, unmounted, or restored from snapshot.4. Build host-ordered preferred segments on Put
When master handles
PutStart, the priority should be:config.preferred_segmentis set, use it exactly as today.config.preferred_segmentsis set, use it exactly as today.client_id -> host_id -> segment_names.Pseudo-code:
5. Host fallback ordering
The host fallback order should be deterministic and stable.
For the first version, sort active
host_ids lexicographically and rotate the list so the writer's host is first.Example:
Writer host orders:
This avoids the common random fallback problem where many writers may randomly fallback to the same remote segment at the same time.
6. Stable segment rotation within a host
If a host has multiple segments, always trying the first segment creates a local hotspot. Instead, the segment order inside each host should use a stable key-based rotation.
Example:
The same rotation is applied independently for each host in the fallback chain.
The resulting segment list for writer on host1 may look like:
This remains deterministic for the same key and topology, while spreading first-choice pressure across segments on the same host.
7. Fallback behavior
The allocation strategy already supports trying preferred segments first and then continuing with fallback allocation if the preferred list cannot satisfy the request.
With host-aware local-first allocation enabled, the preferred list can include all active segments in host fallback order. For
replica_num = 1, this means:For the first implementation, this RFC targets the common KV cache case where
replica_num = 1. Forreplica_num > 1, the behavior should be explicitly defined before enabling this policy by default. A future extension may place the first replica locally and spread additional replicas across different hosts.Configuration
Add a client-side host identity variable:
Add a master/client allocation policy switch. The exact naming can be discussed, but the intended semantics are:
Initial default:
The default can stay disabled for conservative backward compatibility. After the behavior is validated, the community can discuss whether local-first should become the default for Mooncake Store memory allocation.
Compatibility
This proposal is backward-compatible if introduced behind a feature flag.
preferred_segmentandpreferred_segmentskeep their current semantics and override automatic local-first allocation.host_idcontinue to use the current allocation behavior.Segment.namematching behavior is unchanged.Failure and Edge Cases
Writer has no
host_idFallback to current allocation behavior.
Writer host has no active store segment
Skip the writer host and continue with the next hosts in ordered fallback.
Store segment is full
Continue to the next segment in the generated preferred list.
Store host goes down
The host's unavailable segments should be removed from active allocator indexes. The generated preferred list should only include active segments.
Multiple clients on the same physical host
All clients must report the same
host_id. This is the main reason to keephost_idseparate fromlocal_hostname.Multi-NIC and container environments
Operators should set
MOONCAKE_HOST_IDexplicitly. Automatically derived hostnames or IPs are best-effort only.Implementation Plan
This feature is intended to be implemented in one PR with a narrow scope: add host metadata, build automatic local-first preferred segment lists, and verify the allocation behavior. The PR should not include NUMA/GPU-aware placement or topology-aware remote ordering.
Metadata changes
Add
host_idto Mooncake client configuration.Resolve
host_idfromMOONCAKE_HOST_ID, explicit config, or best-effort fallback.Extend the client/master registration or heartbeat path to record
client_id -> host_id.Add
host_idto mounted segment metadata.Maintain master indexes:
Allocation policy
Add a helper to build host-ordered segment lists:
Sort active hosts deterministically.
Rotate host order so writer host is first.
Sort segments within each host deterministically.
Rotate segments within each host using
Hash(key) % segment_count.Use the generated list as
preferred_segmentsonly when explicit preferred segments are absent.Observability
Add minimal logs or metrics for:
This is important for validating whether the new policy actually reduces cross-host writes and whether ordered fallback creates pressure on specific hosts.
Tests
Add unit tests for:
host_idresolution priority.master host indexes on mount, unmount, and remount.
BuildHostOrderedSegmentswith four hosts:stable key-based segment rotation inside one host.
explicit
preferred_segment(s)overriding automatic local-first allocation.missing
host_idfalling back to current behavior.local host with no active segment falling back to the next host.
Add integration tests for:
host_id.Alternatives Considered
Upper layer passes
preferred_segmentvLLM and SGLang can manually set
preferred_segmentorpreferred_segments. This works for controlled deployments, but it requires the upper layer or deployment system to know exact Mooncake segment names. It also does not solve automatic discovery of all local segments.Infer host by
Segment.te_endpointMaster could parse IPs from
te_endpointand group segments by IP. This is fragile in multi-NIC, container, hostname/IP-mixed, and standalone requester scenarios. It also does not provide host identity for clients that do not mount segments.Reuse
local_hostnameas host identityThis breaks when multiple clients on the same physical host use different logical names, for example
hostA-rank0,hostA-rank1, andhostA-store0.host_idshould be a separate field.Keep random fallback
Random fallback is simple, but multiple writers can fallback to the same remote segment or host at the same time. Ordered host fallback provides more predictable behavior and avoids obvious random collision patterns.
Open for Discussion
MOONCAKE_LOCAL_FIRST_ALLOCbe enabled by default after the feature is implemented, or remain opt-in?replica_num > 1behave under local-first allocation?host_idbe stored in snapshots, rebuilt from client registration, or both?prefer_alloc_in_same_node, or introduce a more explicit policy name such aslocal_first_allocation?Before submitting a new issue...
@github-actions[bot] commented on GitHub (Jun 26, 2026):
Thanks for opening this issue, @yokinoshitayoki!
113957881A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide