MCPcopy
hub / github.com/grafana/dskit / benchmarkUpdateRingState

Function benchmarkUpdateRingState

ring/ring_test.go:139–192  ·  view source on GitHub ↗
(b *testing.B, numInstances, numTokens int, updateTokens bool)

Source from the content-addressed store, hash-verified

137}
138
139func benchmarkUpdateRingState(b *testing.B, numInstances, numTokens int, updateTokens bool) {
140 cfg := Config{
141 KVStore: kv.Config{},
142 HeartbeatTimeout: time.Hour, // long timeout to get healthy stats
143 ReplicationFactor: 3,
144 ZoneAwarenessEnabled: true,
145 }
146
147 gen := initTokenGenerator(b)
148
149 // create the ring to set up metrics, but do not start
150 registry := prometheus.NewRegistry()
151 ring, err := NewWithStoreClientAndStrategy(cfg, testRingName, testRingKey, nil, NewDefaultReplicationStrategy(), registry, log.NewNopLogger())
152 require.NoError(b, err)
153
154 // Make a random ring with N instances, and M tokens per ingests
155 // Also make a copy with different timestamps and one with different tokens
156 desc := NewDesc()
157 otherDesc := NewDesc()
158 takenTokens := []uint32{}
159 otherTakenTokens := []uint32{}
160 for i := 0; i < numInstances; i++ {
161 tokens := gen.GenerateTokens(numTokens, takenTokens)
162 takenTokens = append(takenTokens, tokens...)
163 now := time.Now()
164 zeroTime := time.Time{}
165 id := fmt.Sprintf("%d", i)
166 desc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, ACTIVE, now, false, zeroTime, nil)
167 if updateTokens {
168 otherTokens := gen.GenerateTokens(numTokens, otherTakenTokens)
169 otherTakenTokens = append(otherTakenTokens, otherTokens...)
170 otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), otherTokens, ACTIVE, now, false, zeroTime, nil)
171 } else {
172 otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, JOINING, now, false, zeroTime, nil)
173 }
174 }
175
176 if updateTokens {
177 require.Equal(b, Different, desc.RingCompare(otherDesc))
178 } else {
179 require.Equal(b, EqualButStatesAndTimestamps, desc.RingCompare(otherDesc))
180 }
181
182 flipFlop := true
183 b.ResetTimer()
184 for n := 0; n < b.N; n++ {
185 if flipFlop {
186 ring.updateRingState(desc)
187 } else {
188 ring.updateRingState(otherDesc)
189 }
190 flipFlop = !flipFlop
191 }
192}
193
194func TestDoBatchZeroInstances(t *testing.T) {
195 ctx := context.Background()

Callers 1

BenchmarkUpdateRingStateFunction · 0.85

Calls 9

AddIngesterMethod · 0.95
RingCompareMethod · 0.95
initTokenGeneratorFunction · 0.85
NewDescFunction · 0.85
updateRingStateMethod · 0.80
GenerateTokensMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected