Skip to content

Commit 4677e79

Browse files
committed
tablets: colocate gc benchmark with tablet benches
1 parent fd3677b commit 4677e79

2 files changed

Lines changed: 50 additions & 59 deletions

File tree

tablets/gcshape_bench_test.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

tablets/tablets_bench_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package tablets
66
import (
77
"fmt"
88
"runtime"
9+
"runtime/debug"
910
"sync/atomic"
1011
"testing"
1112
)
@@ -65,6 +66,55 @@ func BenchmarkCowTabletList(b *testing.B) {
6566
})
6667
}
6768

69+
func BenchmarkCowTabletListGCShape(b *testing.B) {
70+
const (
71+
rf = 3
72+
hostsCount = 16
73+
tabletsPerTable = 100000
74+
tokenRangeCount = int64(tabletsPerTable)
75+
lookupBatchSize = 2048
76+
gcEveryIterations = 8
77+
)
78+
79+
oldGCPercent := debug.SetGCPercent(10)
80+
defer debug.SetGCPercent(oldGCPercent)
81+
82+
hosts := GenerateHostUUIDs(hostsCount)
83+
cl := NewCowTabletList()
84+
defer cl.Close()
85+
86+
cl.BulkAddTablets(createTablets("ks", "tbl", hosts, rf, tabletsPerTable, tokenRangeCount))
87+
cl.Flush()
88+
89+
runtime.GC()
90+
runtime.GC()
91+
92+
var before, after runtime.MemStats
93+
runtime.ReadMemStats(&before)
94+
95+
b.ResetTimer()
96+
for i := 0; i < b.N; i++ {
97+
for j := 0; j < lookupBatchSize; j++ {
98+
token := int64((i*lookupBatchSize + j) % tabletsPerTable)
99+
_, _ = cl.FindTabletForToken("ks", "tbl", token)
100+
}
101+
if i%gcEveryIterations == 0 {
102+
runtime.GC()
103+
}
104+
}
105+
b.StopTimer()
106+
107+
runtime.GC()
108+
runtime.GC()
109+
runtime.KeepAlive(cl)
110+
runtime.ReadMemStats(&after)
111+
112+
b.ReportMetric(float64(after.HeapObjects), "heap_objects")
113+
b.ReportMetric(float64(after.HeapAlloc), "heap_bytes")
114+
b.ReportMetric(float64(after.NumGC-before.NumGC), "gc_cycles")
115+
b.ReportMetric(float64(after.PauseTotalNs-before.PauseTotalNs), "gc_pause_ns")
116+
}
117+
68118
func runCowTabletListTestSuit(b *testing.B, name string, hostsCount, parallelism, rf, totalTablets, extraTables int) {
69119
b.Run(name, func(b *testing.B) {
70120

0 commit comments

Comments
 (0)