@@ -6,6 +6,7 @@ package tablets
66import (
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+
68118func runCowTabletListTestSuit (b * testing.B , name string , hostsCount , parallelism , rf , totalTablets , extraTables int ) {
69119 b .Run (name , func (b * testing.B ) {
70120
0 commit comments