Skip to content

router: make the kvcache GC configurable and stoppable - #1634

Open
aeron-gh wants to merge 3 commits into
volcano-sh:mainfrom
aeron-gh:router/kvcache-gc-configurable
Open

router: make the kvcache GC configurable and stoppable#1634
aeron-gh wants to merge 3 commits into
volcano-sh:mainfrom
aeron-gh:router/kvcache-gc-configurable

Conversation

@aeron-gh

Copy link
Copy Markdown
Contributor

/kind feature

What this PR does / why we need it:

Makes the kvcache-aware ownership GC configurable, stoppable, and audible, the three things #1580 asks for so its boundary behavior can be exercised by a test rather than waited out for an hour.

  • Knobs. gcInterval, gcFieldFreshDuration and gcScanSize join the existing KVCacheAwareArgs, following the blockSizeToHash pattern. The two durations are strings parsed with time.ParseDuration ("30m"), not time.Duration fields: plugin args go through sigs.k8s.io/yaml, which bridges YAML to JSON, and time.Duration decodes there only as an integer of nanoseconds. Each rejected value logs a warning naming the field, because the surrounding unmarshal drops every argument silently when one of them is malformed.
  • Stop. runGC now selects on a stop channel, and Stop() closes it (idempotent via sync.Once). The scheduler framework has no teardown hook today, so nothing in the router calls this yet; what it buys now is that a plugin built in a test can be torn down between cases instead of leaving an hourly ticker goroutine behind.
  • Error visibility. The three GC error paths (scan, per-key read, delete) move from klog.V(4) to klog.Warningf, so a router at default verbosity says something when GC stops making progress.

A zero-valued KVCacheAware keeps the previous defaults: the three values are read through small helpers that fall back to the existing constants, so the many tests that build the plugin as a struct literal behave exactly as before. kvCacheFieldFreshDuration is still 24h by default, matching the runtime's mapping key expiry documented in kv_cache_manager.py; it is only read by the GC cutoff, never by scoring, which filters owners by container start time.

Which issue(s) this PR fixes:
Fixes #1580

Notes for reviewers:

Does this PR introduce a user-facing change?:

The kvcache-aware plugin accepts gcInterval, gcFieldFreshDuration and gcScanSize arguments, and logs GC failures at warning level.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hzxuzhonghu for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI review requested due to automatic review settings August 16, 2026 06:48

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@LiZhenCheng9527 LiZhenCheng9527 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think these need to be placed in the CRD.
Will there be situations where different KV caches require different GC configurations?

@aeron-gh

Copy link
Copy Markdown
Contributor Author

@LiZhenCheng9527
thanks for the review. no, i do not see a per cache case: the gc is one loop per router process over the shared index, every replica reads the same configmap, so it is one setting per deployment. nothing on the crd side changes, the knobs are configmap plugin args next to the existing kvcache-aware ones, and unset fields keep the 1h, 24h, 100 defaults.

the reason they are config args rather than a test-only hook: the e2e planned in #1328 runs the router as deployed, and the configmap is the only seam a test outside the process can reach to shrink the freshness window to seconds. a unit test can call gcStaleFields directly, an e2e cannot.

if the surface still feels wide, gcScanSize is the one i would fold back into a const, the two durations are what the e2e needs

Copilot AI review requested due to automatic review settings August 19, 2026 09:10

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Signed-off-by: aeron-gh <agab0323@gmail.com>
Signed-off-by: aeron-gh <agab0323@gmail.com>
Comment on lines +89 to +99
// GCInterval overrides how often the ownership GC runs (default 1h).
// Any duration time.ParseDuration accepts, for example "30m".
GCInterval string `yaml:"gcInterval,omitempty"`
// GCFieldFreshDuration overrides how long an ownership field survives without
// a refresh before GC removes it (default 24h), same format as GCInterval.
// The default matches the runtime's mapping key expiry; lowering it only
// shortens how long ownership written by a departed pod lingers, it does not
// affect scoring, which filters owners by container start time.
GCFieldFreshDuration string `yaml:"gcFieldFreshDuration,omitempty"`
// GCScanSize overrides the SCAN COUNT hint per round (default 100).
GCScanSize int64 `yaml:"gcScanSize,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's necessary to write such complicated comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, all one liners now.
same habit as the other pr, working on it :)

@kube-gopher

Copy link
Copy Markdown
Member

/kind enhancement
/remove-kind feature

@volcano-sh-bot volcano-sh-bot added kind/enhancement New feature or request and removed kind/feature labels Aug 27, 2026
Signed-off-by: aeron-gh <agab0323@gmail.com>
Copilot AI review requested due to automatic review settings August 27, 2026 07:04

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

kind/enhancement New feature or request size/L

Projects

Status: Accepted

Development

Successfully merging this pull request may close these issues.

router: kvcache GC knobs are unexported, the loop is unstoppable, and errors are silent below v=4

5 participants