From c37b3202860056855d2abc3b780e4014666bcef4 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 7 Jun 2023 17:55:34 -0700 Subject: [PATCH] add cache names and actually serialize --- deferred-rate-limiter/src/lib.rs | 1 + web3_proxy/src/app/mod.rs | 3 +++ web3_proxy/src/frontend/mod.rs | 1 + web3_proxy/src/frontend/status.rs | 10 ++++------ web3_proxy/src/rpcs/many.rs | 2 ++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/deferred-rate-limiter/src/lib.rs b/deferred-rate-limiter/src/lib.rs index c3603c77..e20511ae 100644 --- a/deferred-rate-limiter/src/lib.rs +++ b/deferred-rate-limiter/src/lib.rs @@ -48,6 +48,7 @@ where // TODO: prefix instead of a static str let local_cache = CacheBuilder::new(cache_size.try_into().unwrap()) .time_to_live(Duration::from_secs(ttl)) + .name(&format!("DeferredRateLimiter-{}", prefix)) .build(); Self { diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 691841bb..664c0c26 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -400,11 +400,13 @@ impl Web3ProxyApp { // TODO: max_capacity from config // TODO: ttl from config let rpc_secret_key_cache = CacheBuilder::new(10_000) + .name("rpc_secret_key") .time_to_live(Duration::from_secs(600)) .build(); // TODO: TTL left low, this could also be a solution instead of modifiying the cache, that may be disgusting across threads / slow anyways let user_balance_cache = CacheBuilder::new(10_000) + .name("user_balance") .time_to_live(Duration::from_secs(600)) .build(); @@ -501,6 +503,7 @@ impl Web3ProxyApp { // TODO: what should we set? 5 minutes is arbitrary. the nodes themselves hold onto transactions for much longer // TODO: this used to be time_to_update, but let pending_transactions = CacheBuilder::new(10_000) + .name("pending_transactions") .time_to_live(Duration::from_secs(300)) .build(); diff --git a/web3_proxy/src/frontend/mod.rs b/web3_proxy/src/frontend/mod.rs index 112f8ef4..9528a189 100644 --- a/web3_proxy/src/frontend/mod.rs +++ b/web3_proxy/src/frontend/mod.rs @@ -54,6 +54,7 @@ pub async fn serve( debug!("response_cache size: {}", response_cache_size); let response_cache: ResponseCache = CacheBuilder::new(response_cache_size as u64) + .name("frontend_response") .time_to_live(Duration::from_secs(1)) .build(); diff --git a/web3_proxy/src/frontend/status.rs b/web3_proxy/src/frontend/status.rs index bb2e840b..f189301a 100644 --- a/web3_proxy/src/frontend/status.rs +++ b/web3_proxy/src/frontend/status.rs @@ -168,14 +168,12 @@ impl<'a, K, V> Serialize for MokaCacheSerializer<'a, K, V> { where S: serde::Serializer, { - let mut state = serializer.serialize_struct("MokaCache", 2)?; - - self.0.weighted_size(); + let mut state = serializer.serialize_struct("MokaCache", 3)?; state.serialize_field("entry_count", &self.0.entry_count())?; + state.serialize_field("name", &self.0.name())?; + state.serialize_field("weighted_size", &self.0.weighted_size())?; - todo!(); - - // state.end() + state.end() } } diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index b5f60012..d6e8c030 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -98,6 +98,7 @@ impl Web3Rpcs { // TODO: actual weighter on this // TODO: time_to_idle instead? let blocks_by_hash: BlocksByHashCache = CacheBuilder::new(1_000) + .name("blocks_by_hash") .time_to_idle(Duration::from_secs(30 * 60)) .build(); @@ -105,6 +106,7 @@ impl Web3Rpcs { // TODO: limits from config // TODO: time_to_idle instead? let blocks_by_number = CacheBuilder::new(1_000) + .name("blocks_by_number") .time_to_idle(Duration::from_secs(30 * 60)) .build();