From 28fa424c2a9f34f5643aabb074d8148a3e5c15d5 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 17 Sep 2022 02:30:06 +0000 Subject: [PATCH] start weighers --- web3_proxy/src/app.rs | 12 ++++++++++-- web3_proxy/src/rpcs/connections.rs | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/web3_proxy/src/app.rs b/web3_proxy/src/app.rs index 37c16674..ba530c5f 100644 --- a/web3_proxy/src/app.rs +++ b/web3_proxy/src/app.rs @@ -254,7 +254,8 @@ impl Web3ProxyApp { // TODO: use this? it could listen for confirmed transactions and then clear pending_transactions, but the head_block_sender is doing that drop(pending_tx_receiver); - // TODO: sized and timed expiration! + // TODO: capacity from configs + // all these are the same size, so no need for a weigher let pending_transactions = Cache::builder() .max_capacity(10_000) .build_with_hasher(ahash::RandomState::new()); @@ -264,9 +265,11 @@ impl Web3ProxyApp { // TODO: we should still have some sort of expiration or maximum size limit for the map // this block map is shared between balanced_rpcs and private_rpcs. - // TODO: what limits should we have for expiration? + // TODO: limits from config + // TODO: these blocks don't have full transactions, but they do have rather variable amounts of transaction hashes let block_map = Cache::builder() .max_capacity(10_000) + .weigher() .build_with_hasher(ahash::RandomState::new()); let (balanced_rpcs, balanced_handle) = Web3Connections::spawn( @@ -338,10 +341,15 @@ impl Web3ProxyApp { } // TODO: change this to a sized cache. theres some potentially giant responses that will break things + // responses can be very different in sizes, so this definitely needs a weigher + // TODO: max_capacity from config let response_cache = Cache::builder() .max_capacity(10_000) + .weigher() .build_with_hasher(ahash::RandomState::new()); + // all the users are the same size, so no need for a weigher + // TODO: max_capacity from config let user_cache = Cache::builder() .max_capacity(10_000) .build_with_hasher(ahash::RandomState::new()); diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index 17b49ce8..92ccdd84 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -175,11 +175,13 @@ impl Web3Connections { let synced_connections = SyncedConnections::default(); - // TODO: sizing and expiration on these caches! + // TODO: max_capacity and time_to_idle from config + // all block hashes are the same size, so no need for weigher let block_hashes = Cache::builder() .time_to_idle(Duration::from_secs(600)) .max_capacity(10_000) .build_with_hasher(ahash::RandomState::new()); + // all block numbers are the same size, so no need for weigher let block_numbers = Cache::builder() .time_to_idle(Duration::from_secs(600)) .max_capacity(10_000)