You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cache is already sharded internally and each shard gets a rwlock. While I haven't tested I presume further gains from sharding the rwlock itself will only be visible in the most extreme of circumstances while hurting the other cases.
The tradeoff is obvious, having faster reads hurts writes (sharding a reader lock into many cache lines means acquiring a write lock becomes more expensive)
However in our case (and probably many other scenarios) caches have low write, high read ratios
The sweet spot where this helps most is in the range between 0 and below 10% writes
Afterwards still helps when there are many threads contending
Seems like the bench threads are accessing the cache in a busy loop ish and a relatively high skew (zipf 1.1)? I don't have access to a 64/128 box but I wonder
if increasing quick cache shard counts help at all
how this translates to feldera usage with threads doing significant work in between cache calls
Either way it looks like there is some opportunity here? I'd take that PR with a compile time feature flag. Seems like crossbeam uses a fixed 8 shard config so in the future quick cache may have its own sharded lock.
bench threads are accessing the cache in a busy loop ish
in the profile I looked at about 30% of time is spent in alloc+zeroing buffer, but otherwise yes a lot of contention on the cache. This isn't always what happens I agree; was trying to show the general problem
a relatively high skew (zipf 1.1)
Yes, zipf is pretty independent of the read-scaling effect from what I can tell
if increasing quick cache shard counts help at all
we fix the shard count to 256
feldera usage with threads doing significant work in between cache calls
it depends, we have different of customers with different settings/pipelines cache access patterns; some run with many threads
Either way it looks like there is some opportunity here?
Activity
arthurprs commentedon Mar 13, 2026
The cache is already sharded internally and each shard gets a rwlock. While I haven't tested I presume further gains from sharding the rwlock itself will only be visible in the most extreme of circumstances while hurting the other cases.
gz commentedon Mar 13, 2026
I understand, but the rwlock themselves are not sharded, if you have a very read heavy workload and many threads it can be a problem because read-locks in general aren't very scalable in rust (https://docs.rs/crossbeam/latest/crossbeam/sync/struct.ShardedLock.html is a bit better)
arthurprs commentedon Mar 13, 2026
I would take such contribution if we can have a representative benchmark showing the benefits.
gz commentedon Mar 13, 2026
here is the branch with the changes https://github.com/gz/quick-cache/tree/sharded-rwlock
using a benchmark in our codebase https://github.com/feldera/feldera/blob/d6a59bb6e17e080c5cea6be0d9a89361143b50d3/crates/dbsp/benches/buffer_cache.rs#L1
Here are the results (machine has 64 cores, 128 threads):
Summary:
let me know if you'd like me to submit a PR.
arthurprs commentedon Mar 16, 2026
Seems like the bench threads are accessing the cache in a busy loop ish and a relatively high skew (zipf 1.1)? I don't have access to a 64/128 box but I wonder
Either way it looks like there is some opportunity here? I'd take that PR with a compile time feature flag. Seems like crossbeam uses a fixed 8 shard config so in the future quick cache may have its own sharded lock.
gz commentedon Mar 18, 2026
in the profile I looked at about 30% of time is spent in alloc+zeroing buffer, but otherwise yes a lot of contention on the cache. This isn't always what happens I agree; was trying to show the general problem
Yes, zipf is pretty independent of the read-scaling effect from what I can tell
we fix the shard count to 256
it depends, we have different of customers with different settings/pipelines cache access patterns; some run with many threads
I think so, I submitted a PR
arthurprs commentedon Mar 19, 2026
Released as part of 0.6.21 under the
sharded-lockfeature flaggz commentedon Mar 19, 2026
Thank you!