File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import (
14
14
"strconv"
15
15
"sync"
16
16
"testing"
17
- "time"
18
17
19
18
"github.com/cockroachdb/pebble/internal/base"
20
19
"github.com/stretchr/testify/require"
@@ -289,10 +288,12 @@ func TestCacheStressSetExisting(t *testing.T) {
289
288
}
290
289
291
290
func BenchmarkCacheGet (b * testing.B ) {
292
- const size = 100000
291
+ const size = 1_000_000
293
292
294
- n := runtime .GOMAXPROCS (0 )
295
- cache := NewWithShards (size * int64 (n ), n )
293
+ // We double the size to allow for shard imbalances. With many objects and
294
+ // relatively few shards, the probability that any bucket is more than double
295
+ // the expected size is vanishingly small.
296
+ cache := New (2 * size )
296
297
defer cache .Unref ()
297
298
h := cache .NewHandle ()
298
299
defer h .Close ()
@@ -303,12 +304,12 @@ func BenchmarkCacheGet(b *testing.B) {
303
304
304
305
b .ResetTimer ()
305
306
b .RunParallel (func (pb * testing.PB ) {
306
- rng := rand .New (rand .NewPCG (0 , uint64 (time .Now ().UnixNano ())))
307
-
307
+ pcg := rand .NewPCG (rand .Uint64 (), rand .Uint64 ())
308
308
for pb .Next () {
309
- v := h .Get (base .DiskFileNum (0 ), uint64 (rng .IntN (size )))
309
+ offset := pcg .Uint64 () % size
310
+ v := h .Get (base .DiskFileNum (0 ), offset )
310
311
if v == nil {
311
- b .Fatal ("failed to lookup value" )
312
+ b .Fatal ("failed to look up value" )
312
313
}
313
314
v .Release ()
314
315
}
You can’t perform that action at this time.
0 commit comments