Skip to content

Commit 5fd1133

Browse files
committed
ref(quotas): Tune quota cache hashmap
1 parent 9657268 commit 5fd1133

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

relay-quotas/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ redis = ["dep:thiserror", "dep:relay-log", "relay-redis/impl"]
1717
workspace = true
1818

1919
[dependencies]
20+
ahash = { workspace = true }
2021
async-trait = { workspace = true }
2122
hashbrown = { workspace = true }
2223
papaya = { workspace = true }

relay-quotas/src/cache.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ where
3030
///
3131
/// The cache is keyed with the individual quota, the value is the last known, currently
3232
/// consumed amount of the quota.
33-
cache: papaya::HashMap<T, CachedQuota>,
33+
cache: papaya::HashMap<T, CachedQuota, ahash::RandomState>,
3434

3535
/// The amount the cache is allowed to opportunistically over-accept based on the remaining
3636
/// quota.
@@ -62,7 +62,14 @@ where
6262
NonZeroUsize::new(max_over_spend_divisor as usize).unwrap_or(NonZeroUsize::MIN);
6363

6464
Self {
65-
cache: Default::default(),
65+
cache: papaya::HashMap::builder()
66+
// `ahash` for a faster hasher
67+
.hasher(ahash::RandomState::new())
68+
// Blocking resizes help with iteration, which we need for cleanups,
69+
// as well as our workload seems to match the description of `Blocking`
70+
// very well.
71+
.resize_mode(papaya::ResizeMode::Blocking)
72+
.build(),
6673
max_over_spend_divisor,
6774
vacuum_interval: Duration::from_secs(30),
6875
// Initialize to 0, this means a vacuum run immediately, but it is going to be fast

0 commit comments

Comments
 (0)