Skip to content

Commit

Permalink
[chore] add queue benchmarks (#8781)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Oct 31, 2023
1 parent adb9413 commit f3d7133
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions exporter/exporterhelper/internal/bounded_memory_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package internal

import (
"context"
"fmt"
"reflect"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -144,6 +145,63 @@ func TestShutdownWhileNotEmpty(t *testing.T) {
assert.Equal(t, 0, q.Size())
}

func Benchmark_QueueUsage_10000_1_50000(b *testing.B) {
queueUsage(b, 10000, 1, 50000)
}

func Benchmark_QueueUsage_10000_2_50000(b *testing.B) {
queueUsage(b, 10000, 2, 50000)
}
func Benchmark_QueueUsage_10000_5_50000(b *testing.B) {
queueUsage(b, 10000, 5, 50000)
}
func Benchmark_QueueUsage_10000_10_50000(b *testing.B) {
queueUsage(b, 10000, 10, 50000)
}

func Benchmark_QueueUsage_50000_1_50000(b *testing.B) {
queueUsage(b, 50000, 1, 50000)
}

func Benchmark_QueueUsage_50000_2_50000(b *testing.B) {
queueUsage(b, 50000, 2, 50000)
}
func Benchmark_QueueUsage_50000_5_50000(b *testing.B) {
queueUsage(b, 50000, 5, 50000)
}
func Benchmark_QueueUsage_50000_10_50000(b *testing.B) {
queueUsage(b, 50000, 10, 50000)
}

func Benchmark_QueueUsage_10000_1_250000(b *testing.B) {
queueUsage(b, 10000, 1, 250000)
}

func Benchmark_QueueUsage_10000_2_250000(b *testing.B) {
queueUsage(b, 10000, 2, 250000)
}
func Benchmark_QueueUsage_10000_5_250000(b *testing.B) {
queueUsage(b, 10000, 5, 250000)
}
func Benchmark_QueueUsage_10000_10_250000(b *testing.B) {
queueUsage(b, 10000, 10, 250000)
}

func queueUsage(b *testing.B, capacity int, numConsumers int, numberOfItems int) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
q := NewBoundedMemoryQueue(capacity, numConsumers)
err := q.Start(context.Background(), componenttest.NewNopHost(), newNopQueueSettings(func(item Request) {
time.Sleep(1 * time.Millisecond)
}))
require.NoError(b, err)
for j := 0; j < numberOfItems; j++ {
q.Produce(newStringRequest(fmt.Sprintf("%d", j)))
}
q.Stop()
}
}

type consumerState struct {
sync.Mutex
t *testing.T
Expand Down

0 comments on commit f3d7133

Please sign in to comment.