Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: tune bloom filter params of snapshot to fit higher tps #179

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading