Skip to content

Commit

Permalink
opt: tune bloom filter params to fit higher tps
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoieh committed Sep 14, 2024
1 parent e3170ae commit 863e2e0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ var (
// Note, bumping this up might drastically increase the size of the bloom
// filters that's stored in every diff layer. Don't do that without fully
// understanding all the implications.
aggregatorMemoryLimit = uint64(4 * 1024 * 1024)
// aggregatorMemoryLimit = uint64(4 * 1024 * 1024)

// aggregatorItemLimit is an approximate number of items that will end up
// in the aggregator layer before it's flushed out to disk. A plain account
// weighs around 14B (+hash), a storage slot 32B (+hash), a deleted slot
// 0B (+hash). Slots are mostly set/unset in lockstep, so that average at
// 16B (+hash). All in all, the average entry seems to be 15+32=47B. Use a
// smaller number to be on the safe side.
aggregatorItemLimit = aggregatorMemoryLimit / 42
// aggregatorItemLimit = aggregatorMemoryLimit / 42

aggregatorItemLimit = uint64(10000 * 128) // target 10k items per difflayer for 100m block gas limit
aggregatorMemoryLimit = aggregatorItemLimit * 42 // approximately 52MB

// bloomTargetError is the target false positive rate when the aggregator
// layer is at its fullest. The actual value will probably move around up
Expand All @@ -61,12 +64,14 @@ var (

// bloomSize is the ideal bloom filter size given the maximum number of items
// it's expected to hold and the target false positive error rate.
bloomSize = math.Ceil(float64(aggregatorItemLimit) * math.Log(bloomTargetError) / math.Log(1/math.Pow(2, math.Log(2))))
// bloomSize = math.Ceil(float64(aggregatorItemLimit) * math.Log(bloomTargetError) / math.Log(1/math.Pow(2, math.Log(2))))
bloomSize = bloomfilter.OptimalM(aggregatorItemLimit, bloomTargetError)

// bloomFuncs is the ideal number of bits a single entry should set in the
// bloom filter to keep its size to a minimum (given it's size and maximum
// entry count).
bloomFuncs = math.Round((bloomSize / float64(aggregatorItemLimit)) * math.Log(2))
// bloomFuncs = math.Round((bloomSize / float64(aggregatorItemLimit)) * math.Log(2))
bloomFuncs = bloomfilter.OptimalK(bloomSize, aggregatorItemLimit)

// the bloom offsets are runtime constants which determines which part of the
// account/storage hash the hasher functions looks at, to determine the
Expand Down

0 comments on commit 863e2e0

Please sign in to comment.