Question: How to pick the optimal number of shards?
I see that the config allows for specifying the number of shards. In your article about the idea behind bigcache, I see some information on how the shards are used. However, I am wondering if you can provide any advice on how to pick the right number of shards. I understand this is probably heavily dependent on how big the cache is, but some guidelines would be amazing. Perhaps this could be included in the README?
Great idea. We can add graph with number of shards and read/write times on axis for different ratio between reeds and writes.
I forgot we already have a benchmark that may be interesting for you.
BenchmarkWriteToCache/2-shards-8 2797872 422 ns/op 593 B/op 3 allocs/op
BenchmarkWriteToCache/4-shards-8 4258088 281 ns/op 606 B/op 2 allocs/op
BenchmarkWriteToCache/8-shards-8 5818146 210 ns/op 592 B/op 3 allocs/op
BenchmarkWriteToCache/16-shards-8 6131810 175 ns/op 590 B/op 3 allocs/op
BenchmarkWriteToCache/32-shards-8 6575697 158 ns/op 589 B/op 3 allocs/op
BenchmarkWriteToCache/64-shards-8 6989594 147 ns/op 619 B/op 2 allocs/op
BenchmarkWriteToCache/128-shards-8 7385629 161 ns/op 615 B/op 3 allocs/op
BenchmarkWriteToCache/256-shards-8 7333994 161 ns/op 616 B/op 3 allocs/op
BenchmarkWriteToCache/512-shards-8 7277818 163 ns/op 617 B/op 3 allocs/op
BenchmarkWriteToCache/1024-shards-8 7104553 165 ns/op 619 B/op 3 allocs/op
BenchmarkReadFromCache/2-shards-8 4684094 254 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/4-shards-8 4718196 259 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/8-shards-8 4728337 267 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/16-shards-8 4730055 263 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/32-shards-8 4727535 264 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/64-shards-8 4758895 263 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/128-shards-8 4779847 264 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/256-shards-8 4743238 268 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/512-shards-8 4632170 291 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCache/1024-shards-8 4678452 266 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/2-shards-8 4774302 271 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/4-shards-8 4691768 256 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/8-shards-8 4659164 261 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/16-shards-8 4678573 266 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/32-shards-8 4064743 261 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/64-shards-8 4733755 293 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/128-shards-8 4658438 261 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/256-shards-8 4752415 267 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/512-shards-8 4730323 266 ns/op 271 B/op 2 allocs/op
BenchmarkReadFromCacheWithInfo/1024-shards-8 4023714 264 ns/op 271 B/op 2 allocs/op
Nevertheless, it might be good to add multidimensional benchmark to compare
- number of shards
- read/write ration
- entry size
- key length
Hadn't seen that one, thanks! Nice to see the difference in speed when writing is much bigger than when reading, depending on the number of shards.