-
Notifications
You must be signed in to change notification settings - Fork 26
/
shardedbackend_benchmark_test.go
61 lines (56 loc) · 1.39 KB
/
shardedbackend_benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package krakendrate
import (
"context"
"fmt"
"testing"
"time"
)
func BenchmarkShardedBackend(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
ttl := time.Millisecond
maxNumToEvict := 1000000 // 1 million * (8 length + 4 ) ~ 12 megs ?
maxNumToKeep := 1000000 //
toEvict := generateTestKeys(maxNumToEvict, 8)
toKeep := generateTestKeys(maxNumToKeep, 8)
bc := buildCounter{}
bcf := bc.builder()
t := []struct {
keep int
evict int
}{
{keep: 100, evict: 100},
{keep: 100, evict: 10000},
{keep: 100, evict: 1000000},
{keep: 10000, evict: 100},
{keep: 10000, evict: 10000},
{keep: 10000, evict: 1000000},
}
for _, tc := range t {
b.Run(fmt.Sprintf("loads_%d_keep_%d_evict_%d", tc.keep*10+tc.evict, tc.keep, tc.evict), func(b *testing.B) {
sb := NewShardedBackend(ctx, 2048, ttl, ttl, 1, PseudoFNV64a, MemoryBackendBuilder)
for i := 0; i < b.N; i++ {
numMax := tc.keep
if tc.evict > tc.keep {
numMax = tc.evict
}
// load all one time
for k := 0; k < numMax; k++ {
if k < tc.keep {
sb.Load(toKeep[k], bcf)
}
if k < tc.evict {
sb.Load(toEvict[k], bcf)
}
}
// now keep loading the to keep 9 times
// it might or might not evict depending on the time it takes
for j := 0; j < 9; j++ {
for k := 0; k < tc.keep; k++ {
sb.Load(toKeep[k], bcf)
}
}
}
})
}
cancel()
}