From 941fa38123a6fd6a3a7cb0d4accc096f20015bea Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 27 Sep 2019 14:12:40 +0200 Subject: [PATCH] ristretto: adjust NumCounters --- trie/ristretto.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/trie/ristretto.go b/trie/ristretto.go index 8d24d01df8..a17fb0fb1d 100644 --- a/trie/ristretto.go +++ b/trie/ristretto.go @@ -32,9 +32,12 @@ type RistrettoCache struct { // NewRistrettoCache create a new ristretto cache with the given // capacity in MB func NewRistrettoCache(capacity int) (*RistrettoCache, error) { + maxBytes := int64(1000 * 1000 * capacity) + // Let's assume an item is around 500 bytes large + approxItems := maxBytes / 500 cache, err := ristretto.NewCache(&ristretto.Config{ - NumCounters: int64(capacity * 10), - MaxCost: int64(1000 * 1000 * capacity), + NumCounters: int64(approxItems * 10), + MaxCost: maxBytes, BufferItems: 64, Metrics: false, KeyToHash: func(key interface{}) uint64 {