Add per-item access count stats (blocking and non-blocking)#128
Merged
Conversation
Add non-blocking API for sync cache
Expose shard_index method
* Add non-blocking methods * Do not leak lcs * Dedicated result * More * Simplify * Cleanup + some docs * Docs * Use a feature flag * Posion lock * Remove feature and more tests * Update src/sync.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Simplify signature * Simplify * clippy * More docs * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/sync.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * AI suggestions * Update src/sync.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Dedicated method with state as an input * Shared state methods * More docs
Owner
|
Good addition, thank you. I was almost considering removing the I may add a short commit to the PR before merging later this week. |
Contributor
Author
Thank you for your feedback. We're building a solution on top of quick-cache that introduces persistence, and having such per-item stats would be beneficial for decision-making during content prioritization. |
…s, document stats overhead
- Fold record_item_hit{,_mut} into arity-overloaded record_hit{,_mut}
arms so each resident hit-site records both counters in one call.
- Re-enable entry_overhead under the stats feature; assert the real
per-cache sizes (sync unchanged, unsync +8 via discriminant niche).
- Document the stats feature's per-entry size and per-hit/miss cost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expose per-item access statistics behind the existing
statsfeature.What
ItemStatsstruct (currently exposingaccess_count) returned by a newitem_statsmethod on the syncCache, theunsync::Cache, and the internalCacheShard.try_item_statson the syncCache: it returnsOk(Some(stats))/Ok(None)likeitem_stats, orErr(LockContention)if the shard lock could not be acquired without blocking — matching the othertry_*methods.access_counttracks how many times an item has been read (get/get_mut/get_value_or_guard/entry) since it became resident. Unlike the internalreferencedeviction counter, it is monotonic per residency and not bounded by the eviction policy. It resets to zero when the slot is reused for a new value.item_statsandtry_item_statsbehave like a peek: they do not affect the item's hotness or its access count, and returnNonewhen the key is not resident.Notes
ItemStatstype are gated behind#[cfg(feature = "stats")], so default builds are unaffected.access_countadds anAtomicU64to eachResident, so theentry_overheadsize test is only asserted when thestatsfeature is disabled.