From acf990858645658ff60b8698a5b76ac0e6c5486c Mon Sep 17 00:00:00 2001 From: Longarithm Date: Wed, 8 Dec 2021 02:16:15 +0300 Subject: [PATCH 1/3] add cache size --- core/store/src/trie/trie_storage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/store/src/trie/trie_storage.rs b/core/store/src/trie/trie_storage.rs index ab51fb9f5c9..830617f04ce 100644 --- a/core/store/src/trie/trie_storage.rs +++ b/core/store/src/trie/trie_storage.rs @@ -119,14 +119,14 @@ impl TrieStorage for TrieMemoryPartialStorage { /// Maximum number of cache entries. #[cfg(not(feature = "no_cache"))] -const TRIE_MAX_CACHE_SIZE: usize = 10000; +const TRIE_MAX_CACHE_SIZE: usize = 100000; #[cfg(feature = "no_cache")] const TRIE_MAX_CACHE_SIZE: usize = 1; /// Values above this size (in bytes) are never cached. /// Note that Trie inner nodes are always smaller than this. -const TRIE_LIMIT_CACHED_VALUE_SIZE: usize = 4000; +const TRIE_LIMIT_CACHED_VALUE_SIZE: usize = 1000; pub struct TrieCachingStorage { pub(crate) store: Arc, From 23ce962f7f8dcf3de21f16db95309074331b4914 Mon Sep 17 00:00:00 2001 From: Longarithm Date: Wed, 8 Dec 2021 03:16:59 +0300 Subject: [PATCH 2/3] reduce cache size --- core/store/src/trie/trie_storage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/store/src/trie/trie_storage.rs b/core/store/src/trie/trie_storage.rs index 830617f04ce..4319d590332 100644 --- a/core/store/src/trie/trie_storage.rs +++ b/core/store/src/trie/trie_storage.rs @@ -119,14 +119,14 @@ impl TrieStorage for TrieMemoryPartialStorage { /// Maximum number of cache entries. #[cfg(not(feature = "no_cache"))] -const TRIE_MAX_CACHE_SIZE: usize = 100000; +const TRIE_MAX_CACHE_SIZE: usize = 50000; #[cfg(feature = "no_cache")] const TRIE_MAX_CACHE_SIZE: usize = 1; /// Values above this size (in bytes) are never cached. /// Note that Trie inner nodes are always smaller than this. -const TRIE_LIMIT_CACHED_VALUE_SIZE: usize = 1000; +const TRIE_LIMIT_CACHED_VALUE_SIZE: usize = 4000; pub struct TrieCachingStorage { pub(crate) store: Arc, From ba4f889e1765219878f68fcba96097ba4fd419d0 Mon Sep 17 00:00:00 2001 From: Longarithm Date: Wed, 8 Dec 2021 17:23:11 +0300 Subject: [PATCH 3/3] add comment --- core/store/src/trie/trie_storage.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/store/src/trie/trie_storage.rs b/core/store/src/trie/trie_storage.rs index 4319d590332..4962e9827bb 100644 --- a/core/store/src/trie/trie_storage.rs +++ b/core/store/src/trie/trie_storage.rs @@ -118,6 +118,10 @@ impl TrieStorage for TrieMemoryPartialStorage { } /// Maximum number of cache entries. +/// It was chosen to fit into RAM well. RAM spend on trie cache should not exceed +/// 50_000 * 4 (number of shards) * TRIE_LIMIT_CACHED_VALUE_SIZE = 800 MB. +/// In our tests on a single shard, it barely occupied 40 MB, which is dominated by state cache size +/// with 512 MB limit. The total RAM usage for a single shard was 1 GB. #[cfg(not(feature = "no_cache"))] const TRIE_MAX_CACHE_SIZE: usize = 50000;