nemo_rl.data_plane.adapters.mooncake_ssd_offload#
mooncake_cpu.ssd_offload: Mooncake’s embedded offload in segment owners.
Mooncake’s master offloads an object only to the SSD of the process owning
the segment that holds it, so every process that owns Mooncake memory runs
offload in its own directory. TQ’s own MooncakeStore.offload is not used:
its single offload client on the driver owns none of the data.
Module Contents#
Functions#
mooncake_master flags for |
|
Set up this process’s Mooncake client for SSD offload. |
|
Make TQ’s puts wait for offload to free memory instead of failing. |
|
Upsert, putting keys that find every segment full again until they fit. |
|
Raise if this process owns memory but TQ never built the offloading store. |
|
Delete offload dirs whose owning process is gone (crash, kill, restart). |
|
Delete this process’s offload directory, if it has one. |
|
The default tenant’s key in a per-key offload file, or None. |
|
Delete offload files under |
|
The master’s SSD-eviction count from its Prometheus |
|
Poll |
|
Watch the master’s |
Data#
API#
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.LOGGER#
‘getLogger(…)’
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.REQUIRED_ENV#
None
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._dir: str | None#
None
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._lock_fd: int | None#
None
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._offloading_store_set_up#
False
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.NO_AVAILABLE_HANDLE#
None
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.PUT_WAIT_S#
600.0
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._FIRST_BACKOFF_S#
0.05
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.PUT_BACKOFF_MAX_S#
1.0
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.EVICTION_COUNTER#
‘master_evict_disk_replica_requests_total’
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._COUNTER_LINE#
‘compile(…)’
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._watch_stop: threading.Event | None#
None
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.SWEEP_INTERVAL_S#
30.0
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._SWEEP_BATCH#
1000
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._TENANT_PREFIX#
‘default\x00’
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._sweep_stop: threading.Event | None#
None
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.master_args( ) tuple[str, ...]#
mooncake_master flags for
ssd_offload; empty when it is off.In Mooncake, offload happens on eviction: past the high watermark the master moves objects to SSD and frees
eviction_ratioof the memory. These replace the no-eviction flags TQ passes (gflags keeps the last occurrence).offload_force_evict=false: an object whose SSD write failed stays in memory rather than being dropped. A fresh object cannot be evicted until its lease expires: TQ’s 999999 ms would pin ~17 min of writes, and even 10 s let a 512 MiB segment fill at 64 MiB/s before anything was evictable (job 1321643). The 1 s lease must cover one wholebatch_get_intocall (up tostaging_buffer_sizeper call), not one key: a slower call fails with LEASE_EXPIRED.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.install(
- cfg: nemo_rl.data_plane.interfaces.MooncakeCpuConfig,
- segment_size: int | None,
Set up this process’s Mooncake client for SSD offload.
No-op unless offload is on. Every client’s puts then wait for memory (:func:
wait_for_memory_on_put). A process that owns memory also offloads to its own SSD directory: TQ’s client callssetupwith no offload arguments, so this swaps the store class it builds for one that adds them. Each owner gets a fresh, owner-only<path>/nemo_rl_mooncake_offload/<ray job>-<pid>-<random>, locked for its lifetime: no live run can pick up, or wipe, another’s files, and dirs whose owner died are removed here. Must run before the store is set up.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.wait_for_memory_on_put(client_cls: Any) None#
Make TQ’s puts wait for offload to free memory instead of failing.
TQ’s
_batch_upsert_with_retrygives up after 3 x 1 s. Raising TQ’sMAX_RETRIESinstead would also retry permanent errors, logging each at ERROR. Patchesclient_clsonce.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.upsert_waiting_for_memory(
- upsert: collections.abc.Callable[[list[str], list[int], list[int]], Any],
- keys: list[str],
- ptrs: list[int],
- sizes: list[int],
- *,
- on_error: collections.abc.Callable[[list[str], list[int], list[int], list[int]], None],
Upsert, putting keys that find every segment full again until they fit.
Mooncake admits a put only into free segment memory, while offload frees memory later, in the background.
upsertreturns one status per key; keys answeredNO_AVAILABLE_HANDLEare put again with capped backoff for up toPUT_WAIT_S, with one warning.on_error(keys, ptrs, sizes, statuses)gets the keys that failed any other way.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._pick(
- columns: tuple[list[Any], ...],
- indexes: list[int],
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.require_offloading_store() None#
Raise if this process owns memory but TQ never built the offloading store.
The swap in :func:
installworks only while TQ looks the store class up by name; call this after connecting, when TQ has built its store.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._hold_dir_lock(path: str) None#
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._remove_stale_dirs(parent: str) None#
Delete offload dirs whose owning process is gone (crash, kill, restart).
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.remove_dir() None#
Delete this process’s offload directory, if it has one.
Call only once nothing will read this process’s data again: the files may be the only copy of offloaded objects.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._file_key(path: str) str | None#
The default tenant’s key in a per-key offload file, or None.
The file holds a protobuf KVEntry whose field 1 is the tenant, a NUL, then the key; the file name replaces the NUL and filesystem-unsafe characters with
_, so it cannot be mapped back. Other tenants’ files are skipped.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.sweep_cleared_files(
- root: str,
- exists: collections.abc.Callable[[list[str]], list[int]],
Delete offload files under
rootwhose key the master no longer has.existsisbatch_is_exist: 1 present, 0 absent, negative on error. A file is deleted only on an explicit 0 and only if it is unchanged since it was listed (before the check): a key re-put and offloaded again after the check rewrites its file, which is then kept. Returns the count deleted.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._stamp(path: str) tuple[int, int, int] | None#
- nemo_rl.data_plane.adapters.mooncake_ssd_offload._start_sweep(store: Any, root: str) None#
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.disk_evictions(metrics_text: str) int#
The master’s SSD-eviction count from its Prometheus
/metricstext.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.watch_disk_evictions(
- read: collections.abc.Callable[[], int],
- path: str,
- *,
- interval_s: float = 30.0,
- on_eviction: collections.abc.Callable[[], None] = _thread.interrupt_main,
Poll
readand stop the run at the first SSD eviction.Mooncake’s per-key backend deletes the oldest offloaded files once the disk is nearly full and cannot be told not to (0.3.13), and a deleted file may be the only copy of an object. The default
on_evictioninterrupts this process’s main thread, ending the run. Returns an event that stops the watcher when set; the watcher also sets it once it has fired.
- nemo_rl.data_plane.adapters.mooncake_ssd_offload.watch_master_disk_evictions(metrics_url: str, path: str) None#
Watch the master’s
/metricsatmetrics_urlfrom this process.