From 46bf3825f10e15b3d0e66381ff8eba0f6e8e0162 Mon Sep 17 00:00:00 2001 From: Anton Puhach Date: Wed, 10 Jan 2024 15:24:58 +0100 Subject: [PATCH 1/2] impl --- core/store/src/config.rs | 15 ++++++++++----- core/store/src/trie/config.rs | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/store/src/config.rs b/core/store/src/config.rs index daf62f2bee2..799fa95fcb0 100644 --- a/core/store/src/config.rs +++ b/core/store/src/config.rs @@ -240,17 +240,22 @@ impl Default for StoreConfig { block_size: bytesize::ByteSize::kib(16), trie_cache: TrieCacheConfig { - default_max_bytes: DEFAULT_SHARD_CACHE_TOTAL_SIZE_LIMIT, + default_max_bytes: 500_000_000, // Temporary solution to make contracts with heavy trie access // patterns on shard 3 more stable. It was chosen by the estimation // of the largest contract storage size we are aware as of 23/08/2022. // Consider removing after implementing flat storage. (#7327) // Note: on >= 1.34 nearcore version use 1_000_000_000 if you have // minimal hardware. - per_shard_max_bytes: HashMap::from_iter([( - ShardUId { version: 1, shard_id: 3 }, - 3_000_000_000, - )]), + per_shard_max_bytes: HashMap::from_iter([ + (ShardUId { version: 1, shard_id: 3 }, 3_000_000_000), + // After resharding "token.sweat" account moves to shard 4 + (ShardUId { version: 2, shard_id: 4 }, 3_000_000_000), + // Shard 1 is dedicated to aurora and it had very few cache + // misses even with cache size of only 50MB + (ShardUId { version: 1, shard_id: 1 }, 50_000_000), + (ShardUId { version: 2, shard_id: 1 }, 50_000_000), + ]), shard_cache_deletions_queue_capacity: DEFAULT_SHARD_CACHE_DELETIONS_QUEUE_CAPACITY, }, diff --git a/core/store/src/trie/config.rs b/core/store/src/trie/config.rs index c2a5c4e59f6..49630a74196 100644 --- a/core/store/src/trie/config.rs +++ b/core/store/src/trie/config.rs @@ -7,9 +7,9 @@ use tracing::error; /// Default memory limit, if nothing else is configured. /// It is chosen to correspond roughly to the old limit, which was -/// 500k entries * TRIE_LIMIT_CACHED_VALUE_SIZE. +/// 50k entries * TRIE_LIMIT_CACHED_VALUE_SIZE. pub(crate) const DEFAULT_SHARD_CACHE_TOTAL_SIZE_LIMIT: u64 = - if cfg!(feature = "no_cache") { 1 } else { 500_000_000 }; + if cfg!(feature = "no_cache") { 1 } else { 50_000_000 }; /// Capacity for the deletions queue. /// It is chosen to fit all hashes of deleted nodes for 3 completely full blocks. From 61de47bb235b6d63fee14a4f9e62a6866b27abd8 Mon Sep 17 00:00:00 2001 From: Anton Puhach Date: Fri, 12 Jan 2024 11:03:13 +0100 Subject: [PATCH 2/2] review comments --- core/store/src/config.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/store/src/config.rs b/core/store/src/config.rs index 799fa95fcb0..e340dcb0af3 100644 --- a/core/store/src/config.rs +++ b/core/store/src/config.rs @@ -241,15 +241,17 @@ impl Default for StoreConfig { trie_cache: TrieCacheConfig { default_max_bytes: 500_000_000, - // Temporary solution to make contracts with heavy trie access - // patterns on shard 3 more stable. It was chosen by the estimation - // of the largest contract storage size we are aware as of 23/08/2022. - // Consider removing after implementing flat storage. (#7327) - // Note: on >= 1.34 nearcore version use 1_000_000_000 if you have - // minimal hardware. + // TODO(resharding) The cache size needs to adjusted for every resharding. + // Make that automatic e.g. by defining the minimum cache size per account rather than shard. per_shard_max_bytes: HashMap::from_iter([ + // Temporary solution to make contracts with heavy trie access + // patterns on shard 3 more stable. It was chosen by the estimation + // of the largest contract storage size we are aware as of 23/08/2022. + // Note: on >= 1.34 nearcore version use 1_000_000_000 if you have + // minimal hardware. + // In simple nightshade the heavy contract "token.sweat" is in shard 3 (ShardUId { version: 1, shard_id: 3 }, 3_000_000_000), - // After resharding "token.sweat" account moves to shard 4 + // In simple nightshade v2 the heavy contract "token.sweat" is in shard 4 (ShardUId { version: 2, shard_id: 4 }, 3_000_000_000), // Shard 1 is dedicated to aurora and it had very few cache // misses even with cache size of only 50MB