From f3d71332268b518097b0c819727ceb4e00d0a1c8 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Tue, 31 Oct 2023 10:00:27 -0700 Subject: [PATCH] [chore] add queue benchmarks (#8781) --- .../internal/bounded_memory_queue_test.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/exporter/exporterhelper/internal/bounded_memory_queue_test.go b/exporter/exporterhelper/internal/bounded_memory_queue_test.go index 3fae32025a9..04f641346b1 100644 --- a/exporter/exporterhelper/internal/bounded_memory_queue_test.go +++ b/exporter/exporterhelper/internal/bounded_memory_queue_test.go @@ -7,6 +7,7 @@ package internal import ( "context" + "fmt" "reflect" "sync" "sync/atomic" @@ -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