Skip to content

[Store] Measure SSD prefetch usefulness and export SsdMetric prefetch counters - #5943

Open
DHX98 wants to merge 1 commit into
kvcache-ai:mainfrom
DHX98:feat/5458-prefetch-usefulness-metrics
Open

DHX98 wants to merge 1 commit into
kvcache-ai:mainfrom
DHX98:feat/5458-prefetch-usefulness-metrics

Conversation

@DHX98

@DHX98 DHX98 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Addresses #5458 ("Measure whether prefetch was useful") with zero RPC wire/signature changes and zero per-key Prometheus labels.

Changes

  1. Master bounded-window prefetch usefulness attribution (route::ObjectState, master_config.h, master_service.cpp, master_metric_manager.h/.cpp):
    • Adds prefetch_usefulness_window_ms (default 300000 ms, configurable via master config / CLI flag).
    • Stamps ObjectState::PrefetchAttribution on NotifyPromotionSuccess when the completed task originated from prefetch (from_prefetch), incrementing master_prefetch_promoted{_bytes}_total.
    • Attributes real Get reads in ReadReplicaList / ReadFollowUps (excluding ExistKey and read-only admin queries, counted at most once per prefetched promotion), incrementing master_prefetch_served_by_get{_bytes}_total (or master_prefetch_expired_unconsumed{_bytes}_total if past the usefulness window).
    • Hooks ImmediateReclaimer and OpLogReclaimer to record master_prefetch_evicted_before_use{_bytes}_total when a prefetched MEMORY replica is evicted before any Get consumes it.
    • Records master_prefetch_dropped_under_pressure{_bytes}_total on RegisterPrefetchTask / PromotionAllocStart backpressure rejections.
  2. Client SsdMetric Prometheus export (client_metric.h):
    • Wires mooncake_ssd_prefetch_{complete,complete_bytes,fail,dropped_pressure,dropped_pressure_bytes}_total into SsdMetric::serialize() so holder-side prefetch outcomes are visible on /metrics.
  3. OffsetAllocatorStorageBackend::GetObjectDataSize() (storage_backend.h/.cpp):
    • Implements GetObjectDataSize() on OffsetAllocatorStorageBackend so SSD prefetch size discovery works beyond BucketStorageBackend.

Suggested Merge Priority

  • P0 — Urgent: Critical security vulnerability, data loss/corruption, or widespread production outage requiring immediate action
  • P1 — High: Significant correctness or stability issue in existing functionality, or a regression blocking users without a practical workaround
  • P2 — Normal: Routine bug fix, validated performance/compatibility improvement, or new feature for a confirmed use case
  • P3 — Low: Experimental feature, optional enhancement, refactoring, or cleanup with no urgent user impact

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

  • Unit tests (CPU/TCP + -DUSE_ASCEND_DIRECT=ON on Ascend 950DT):
    • prefetch_task_master_test (added 4 tests covering served_by_get at-most-once + ExistKey exclusion, evicted_before_use, expired_unconsumed, and dropped_under_pressure) — PASS
    • promotion_on_hit_test, prefetch_throttle_test, prefetch_teardown_test, ssd_metrics_test, storage_backend_test (49/49 OffsetAllocatorStorageBackend tests) — ALL PASS
  • Live Enterprise NVMe + Prometheus /metrics E2E (Ascend 950DT host, mooncake_master --metrics_port=... + mooncake_client --enable_http_server=true):
    • Scenario 1 (Prefetch -> Get): master_prefetch_promoted_total=1 (1,048,576 B), master_prefetch_served_by_get_total=1 (1,048,576 B) (unchanged by is_exist and a second get), mooncake_ssd_prefetch_complete_total=1, NVMe 1 MiB read latency 113 us.
    • Scenario 2 (Prefetch -> Evicted Before Use): master_prefetch_promoted_total=1 (1,048,576 B), master_prefetch_served_by_get_total=0, master_prefetch_evicted_before_use_total=1 (1,048,576 B), mooncake_ssd_prefetch_complete_total=1, NVMe 1 MiB read latency 116 us.

Test commands:

ctest --test-dir build --output-on-failure -R "^(prefetch_task_master_test|promotion_on_hit_test|prefetch_throttle_test|prefetch_teardown_test|ssd_metrics_test|storage_backend_test)$"
./scripts/code_format.sh --check --changed-lines --base origin/main

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (live NVMe + Prometheus /metrics verification)

Checklist

  • Every commit I contribute includes my Signed-off-by trailer certifying the DCO
  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue ([RFC]: [Store] SSD/DFS performance optimization roadmap #5458)

AI Assistance Disclosure

  • AI tools were used. The human submitter has reviewed and can defend every changed line.

… counters (kvcache-ai#5458)

Implements Track 1 observability for kvcache-ai#5458:
- Track bounded-window prefetch attribution on route::ObjectState
  (prefetch_usefulness_window_ms, default 300000ms) across
  NotifyPromotionSuccess, ReadReplicaList/ReadFollowUps (real Get only,
  counted at most once), ImmediateReclaimer/OpLogReclaimer (evicted before
  use), and RegisterPrefetchTask/PromotionAllocStart (dropped under
  pressure).
- Export zero-per-key-label Prometheus counters in MasterMetricManager and
  SsdMetric::serialize().
- Implement OffsetAllocatorStorageBackend::GetObjectDataSize().

Signed-off-by: dhx98 <haox.dai@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor
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-11-29T04:04:40.170770Z 27e3b6e 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.

@github-actions github-actions Bot added the size/M 100-1000 changed lines (additions + deletions) label Nov 29, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27e3b6ed55

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +4771 to +4772
if (served_from_prefetched_mem) {
follow_ups.ConsumePrefetch(tenant_id, key, target_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude write-side metadata probes from Get attribution

If a duplicate Client::Put targets a prefetched key, healDanglingLocalDiskReplica() unconditionally calls GetReplicaList (client_service.cpp:2322) before checking whether a MEMORY replica exists. That metadata-only lookup reaches this block, increments served_by_get, and clears the attribution even though no Get or data transfer occurred; batch-Put healing has the same problem. This also prevents a subsequent eviction from being counted as unused, biasing the usefulness measurements. Move these non-read callers to the read-only lookup path or otherwise distinguish them before consuming attribution.

Useful? React with 👍 / 👎.

Comment on lines +9541 to +9545
accessor.GetState().prefetch_attribution =
route::ObjectState::PrefetchAttribution{
.replica_id = staged_replica_id,
.bytes = completed_bytes,
.promoted_at = std::chrono::steady_clock::now()};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expire unused attribution when the usefulness window elapses

For prefetched keys that remain resident but are never read, this record survives indefinitely after the usefulness window expires. Its only processing paths are ConsumePrefetchAttribution and AccountPrefetchEvictedBeforeUse, which require a later lookup or eviction; the background cleanup paths do not expire it. Consequently, master_prefetch_expired_unconsumed_total remains zero for precisely these unused prefetches, and the tracking allocation lasts for the object's lifetime rather than the configured window. Add expiry processing independent of subsequent reads or eviction.

Useful? React with 👍 / 👎.

Comment on lines +1832 to +1833
const size_t remaining = keys.size() - i - 1;
int64_t dropped_bytes = size > 0 ? size : 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for pressure-skipped keys in the outer batch

When a multi-key prefetch hits DRAM pressure, the production caller RegisterAndPromote() invokes PrefetchKeys({keys[i]}, {sizes[i]}) one key at a time and then breaks its own loop on pressure. Therefore, remaining here is always zero on that path, and all unattempted keys in the outer batch disappear from the new dropped-count and dropped-byte metrics. An isolated probe using these functions confirmed that a four-key request totaling 10,240 bytes reports only one dropped key and 1,024 bytes when the first allocation fails. Account for the outer batch's remainder where that loop aborts.

Useful? React with 👍 / 👎.

Comment on lines +211 to +212
// 0 disables usefulness attribution.
uint64_t prefetch_usefulness_window_ms = 300000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Load the usefulness-window setting during master startup

Setting prefetch_usefulness_window_ms: 0 or another window in the master's configuration file has no effect. The standalone master's InitMasterConf() explicitly loads configuration fields but never reads this new one, and LoadConfigFromCmdline() does not assign it either. Normal startup therefore always passes the default 300000 to the service; disabling attribution or tuning the measurement window only works for callers that construct the configuration programmatically. Wire the setting into the production configuration-loading path alongside these struct additions.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M 100-1000 changed lines (additions + deletions) Store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant