(b *testing.B)
| 17 | ) |
| 18 | |
| 19 | func BenchmarkGetNextRequest(b *testing.B) { |
| 20 | const maxOutstandingPerTenant = 2 |
| 21 | const numTenants = 50 |
| 22 | const queriers = 5 |
| 23 | |
| 24 | queues := make([]*RequestQueue, 0, b.N) |
| 25 | |
| 26 | for b.Loop() { |
| 27 | queue := NewRequestQueue(maxOutstandingPerTenant, |
| 28 | prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"user", "priority", "type"}), |
| 29 | prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"user", "priority"}), |
| 30 | MockLimits{MaxOutstanding: 100}, |
| 31 | nil, |
| 32 | ) |
| 33 | queues = append(queues, queue) |
| 34 | |
| 35 | for ix := range queriers { |
| 36 | queue.RegisterQuerierConnection(fmt.Sprintf("querier-%d", ix)) |
| 37 | } |
| 38 | |
| 39 | for range maxOutstandingPerTenant { |
| 40 | for j := range numTenants { |
| 41 | userID := strconv.Itoa(j) |
| 42 | |
| 43 | err := queue.EnqueueRequest(userID, MockRequest{}, 0, nil) |
| 44 | if err != nil { |
| 45 | b.Fatal(err) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | ctx := context.Background() |
| 52 | |
| 53 | for i := 0; b.Loop(); i++ { |
| 54 | idx := FirstUser() |
| 55 | for range maxOutstandingPerTenant * numTenants { |
| 56 | querier := "" |
| 57 | b: |
| 58 | // Find querier with at least one request to avoid blocking in getNextRequestForQuerier. |
| 59 | for _, q := range queues[i].queues.userQueues { |
| 60 | for qid := range q.queriers { |
| 61 | querier = qid |
| 62 | break b |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | _, nidx, err := queues[i].GetNextRequestForQuerier(ctx, idx, querier) |
| 67 | if err != nil { |
| 68 | b.Fatal(err) |
| 69 | } |
| 70 | idx = nidx |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func BenchmarkQueueRequest(b *testing.B) { |
| 76 | const maxOutstandingPerTenant = 2 |
nothing calls this directly
no test coverage detected