Skip to content

Commit

Permalink
fix: increase trie cache size (#5706)
Browse files Browse the repository at this point in the history
Increase trie cache size to mitigate receipts undercharging issue.

## Validity

We can increase cache size to 50_000, so the theoretical occupied size is 50_000 * 4 (num_shards) * 4_000 = 800 MB.

In reality, `/usr/bin/time -v ` shows **520 -> 1070 MB** RAM growth which seem to be caused by #5212. This change have an impact like 30 MB.
I've additionally checked that cache is full on my runs.

## Speedup

On the sample of 30 receipts we considered, we have the following characteristics:

```
default settings: summary time = 3.3s, avg undercharging = 101
increase state cache size: summary time = 0.67s, avg undercharging = 21
increase state cache size + trie cache size = 50k: summary time = 0.5s, avg undercharging = 11.5
increase state cache size + trie cache size = 100k + reduce max value size to 1k: summary time = 0.3s, avg undercharging = 6.9
```

For now, let's just increase cache size. On this sample we reduce undercharging 2x and summary execution time 1.3x.

## Testing

* checking that cache is full;
* existing tests,
* estimating `/usr/bin/time -v ./state-viewer apply_range --start_index 54051433 --end_index 54053438 --shard_id 3`
  • Loading branch information
Longarithm authored and bowenwang1996 committed Dec 20, 2021
1 parent 1eaa01d commit f41190e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/store/src/trie/trie_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ 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 = 10000;
const TRIE_MAX_CACHE_SIZE: usize = 50000;

#[cfg(feature = "no_cache")]
const TRIE_MAX_CACHE_SIZE: usize = 1;
Expand Down

0 comments on commit f41190e

Please sign in to comment.