[balance-overrides] replace cached with moka for caching#4418
[balance-overrides] replace cached with moka for caching#4418ashleychandy wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the cached crate with moka for strategy caching within the balance-overrides crate. It introduces a thread-safe Cache wrapper around moka::sync::Cache, eliminating the need for manual Mutex management in the approval and balance detectors. No critical issues found.
|
As this is a performance improvement (which we've discussed before) what would be your testing plan for this? Where would you put metrics before and after so that I could ship both to prod and measure between the two? |
5b3ed18 to
872c9a0
Compare
|
Good point. I put together a separate branch for benchmarking/instrumentation work so I didn’t have to bloat the main PR with experimental code. Branch: It includes:
The synthetic concurrent-read benchmark came out around:
Benchmark command: cargo test -p balance-overrides compare_moka_vs_mutex_cache -- --ignored --nocaptureThough I understand the real validation still needs to come from production metrics rather than the local benchmark itself. Do these sound like the right signals to monitor? |
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
| V: Clone + Send + Sync + 'static, | ||
| { | ||
| pub(crate) fn new(max_capacity: u64) -> Self { | ||
| let data = moka::sync::Cache::builder() |
There was a problem hiding this comment.
Should ensure the same admission and eviction policy is used for cache replacement (at least initially or otherwise indicated) so that they are still handling what gets cached the same way.
I think the equivalent here is:
let data = moka::sync::Cache::builder()
.max_capacity(max_capacity)
.eviction_policy(EvictionPolicy::lru())
.build();
squadgazzz
left a comment
There was a problem hiding this comment.
LGTM, assuming all the pending comments are addressed.
|
@jmg-duarte @squadgazzz Thanks for the review. I've addressed the pending comments and applied the suggested changes |
MartinquaXD
left a comment
There was a problem hiding this comment.
Change makes sense to me. Just a minor nit. 👍
|
@MartinquaXD Thanks for the suggestion. Propagated cache_size as u64 up to the config boundary |

Description
Replaces
cached::SizedCachewithmoka::sync::Cacheinbalance-overrides.cached::SizedCacherequired external synchronization viaMutex, whilemoka::sync::Cacheis internally concurrent and allows direct cache access without locking boilerplate.Changes
cache.rswrapper aroundmoka::sync::Cache<K, V>Mutex<SizedCache<K, V>>withCache<K, V>lock().unwrap()and migratedcache_get/cache_settocache.get()/insert()cachedand cleaned up related transitive dependencies.insert()calls