Skip to content

Commit

Permalink
Fix(cache): Fix the way we calculate NumCounters.
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain committed Oct 1, 2020
1 parent 8e06ab6 commit 6094fed
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ func Open(opt Options) (db *DB, err error) {
}()

if opt.BlockCacheSize > 0 {
numInCache := opt.BlockCacheSize / int64(opt.BlockSize)

config := ristretto.Config{
// Use 5% of cache memory for storing counters.
NumCounters: int64(float64(opt.BlockCacheSize) * 0.05 * 2),
MaxCost: int64(float64(opt.BlockCacheSize) * 0.95),
NumCounters: numInCache * 8,
MaxCost: opt.BlockCacheSize,
BufferItems: 64,
Metrics: true,
OnExit: table.BlockEvictHandler,
Expand All @@ -342,10 +343,13 @@ func Open(opt Options) (db *DB, err error) {
}

if opt.IndexCacheSize > 0 {
// Index size is around 5% of the table size.
indexSz := int64(float64(opt.MaxTableSize) * 0.05)
numInCache := opt.IndexCacheSize / indexSz

config := ristretto.Config{
// Use 5% of cache memory for storing counters.
NumCounters: int64(float64(opt.IndexCacheSize) * 0.05 * 2),
MaxCost: int64(float64(opt.IndexCacheSize) * 0.95),
NumCounters: numInCache * 8,
MaxCost: opt.IndexCacheSize,
BufferItems: 64,
Metrics: true,
}
Expand Down

0 comments on commit 6094fed

Please sign in to comment.