Skip to content

Commit cad6e5b

Browse files
authored
feat(cache): Add budget manager for cache capacity control (#7399)
Signed-off-by: fimanishi <fimanishi@gmail.com> <!-- Describe what has changed in this PR --> **What changed?** Added a generic budget manager for cache capacity control with the following features: - Two-tier soft cap logic: Capacity is split into free space (shared) and fair share (per-cache) tiers based on a configurable threshold - Per-cache usage tracking: Mutex-based tracking of bytes/count usage for each cache - Two admission modes: Optimistic (add-then-undo) and Strict (CAS pre-check) - Two reclaim patterns: Self-release (cache calls Release per-item) and Manager-release (manager calls Release once with totals) - Callback-based wrappers: Reserve/Release/Reclaim methods with automatic cleanup on errors <!-- Tell your future self why have you made these changes --> **Why?** To provide a unified, host-scoped budget management system that can be shared across multiple caches (both evicting and non-evicting) with: 1. Fair resource allocation: Prevents any single cache from monopolizing capacity through the two-tier soft cap system 2. Flexible integration: Supports different cache eviction patterns (self-release vs manager-release) and admission policies (optimistic vs strict) 3. Safe concurrent access: Mutex-based per-cache tracking combined with atomic global counters ensures thread-safety <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** Unit tests. More tests will be done when the manager is used by the replication cache. <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** No risk. This is just the manager implementation. It is not being used. <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** Added new budget manager for cache capacity control. No migration required - this is a new internal component that can be optionally adopted by existing caches. New metrics available: - `cadence_budget_manager_capacity_bytes/count` - `cadence_budget_manager_used_bytes/count` - `cadence_budget_manager_soft_threshold` - `cadence_budget_manager_active_cache_count` - `cadence_budget_manager_hard_cap_exceeded` - `cadence_budget_manager_soft_cap_exceeded` <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes** --------- Signed-off-by: fimanishi <fimanishi@gmail.com>
1 parent 56e1bbc commit cad6e5b

File tree

5 files changed

+3572
-0
lines changed

5 files changed

+3572
-0
lines changed

0 commit comments

Comments
 (0)