Conversation
|
Thank you for the PR.
If applicable, can you share more detail about this use case? I wonder if it should be covered in more ways. |
There was a problem hiding this comment.
Pull request overview
Exposes a new Cache::shard_index API in the sync cache implementation so callers can determine which internal shard a key maps to, while deduplicating shard-selection logic.
Changes:
- Added
pub fn shard_index<Q: Hash + ?Sized>(&self, key: &Q) -> usizeonCache. - Extracted
compute_shard_index(&self, hash: u64)helper to share the rotate+mask logic withshard_for.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
I have significant tail latency caused by the write workflow (insert/eviction). While backpressure is necessary, I want to do it selectively — respecting shard boundaries to maintain high overall throughput while protecting individual shards from overload. By identifying which shard a key belongs to, I can track per-shard load independently and apply backpressure only where needed, leaving unaffected shards free to operate at full capacity. |
Overview
Exposes a
shard_indexmethod on theCachestruct, allowing callers to determine which internal shard a given key maps to.Motivation
Users who want to observe key distribution or batch operations against the same shard currently have no way to do this without re-implementing the shard selection logic themselves.
Changes
pub fn shard_index<Q: Hash + ?Sized>(&self, key: &Q) -> usizetoCachecompute_shard_index(&self, hash: u64)helper to deduplicate the rotate+mask logic shared withshard_for[0, num_shards())Use cases
Notes
BuildHashersupplied at construction; two caches built with different hashers may map the same key to different shards.?Sizedbound allows calling with unsized types (str,[u8]) consistent with all other key-taking methods.