MCPcopy Create free account
hub / github.com/cortexproject/cortex / AddSeriesConcurrentBench

Function AddSeriesConcurrentBench

pkg/util/limiter/query_limiter_test.go:148–189  ·  view source on GitHub ↗
(b *testing.B, batchSize int)

Source from the content-addressed store, hash-verified

146}
147
148func AddSeriesConcurrentBench(b *testing.B, batchSize int) {
149 b.ResetTimer()
150 const (
151 metricName = "test_metric"
152 )
153
154 limiter := NewQueryLimiter(b.N+1, 0, 0, 0)
155
156 // Concurrent goroutines trying to add duplicated series
157 const numWorkers = 100
158 var wg sync.WaitGroup
159
160 worker := func(w int) {
161 defer wg.Done()
162 var series []labels.Labels
163 for i := 0; b.Loop(); i++ {
164 series = append(series,
165 labels.FromMap(map[string]string{
166 labels.MetricName: metricName + "_1",
167 "series1": fmt.Sprint(i),
168 }))
169 }
170
171 for i := 0; i < len(series); i += batchSize {
172 s := make([][]cortexpb.LabelAdapter, 0, batchSize)
173 j := min(i+batchSize, len(series))
174 for k := i; k < j; k++ {
175 s = append(s, cortexpb.FromLabelsToLabelAdapters(series[k]))
176 }
177
178 err := limiter.AddSeries(s...)
179 assert.NoError(b, err)
180 }
181 }
182
183 for w := 1; w <= numWorkers; w++ {
184 wg.Add(1)
185 go worker(w)
186 }
187
188 wg.Wait()
189}

Calls 7

AddSeriesMethod · 0.95
NewQueryLimiterFunction · 0.85
DoneMethod · 0.80
LoopMethod · 0.80
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected