MCPcopy
hub / github.com/redis/go-redis / BenchmarkPubSubConcurrentCreation

Function BenchmarkPubSubConcurrentCreation

pool_pubsub_bench_test.go:240–271  ·  view source on GitHub ↗

BenchmarkPubSubConcurrentCreation benchmarks concurrent PubSub creation

(b *testing.B)

Source from the content-addressed store, hash-verified

238
239// BenchmarkPubSubConcurrentCreation benchmarks concurrent PubSub creation
240func BenchmarkPubSubConcurrentCreation(b *testing.B) {
241 ctx := context.Background()
242 client := benchmarkClient(32)
243 defer client.Close()
244
245 concurrencyLevels := []int{1, 2, 4, 8, 16}
246
247 for _, concurrency := range concurrencyLevels {
248 b.Run(fmt.Sprintf("Concurrency_%d", concurrency), func(b *testing.B) {
249 b.ResetTimer()
250 b.ReportAllocs()
251
252 var wg sync.WaitGroup
253 semaphore := make(chan struct{}, concurrency)
254
255 for i := 0; i < b.N; i++ {
256 wg.Add(1)
257 semaphore <- struct{}{}
258
259 go func() {
260 defer wg.Done()
261 defer func() { <-semaphore }()
262
263 pubsub := client.Subscribe(ctx, "test-channel")
264 pubsub.Close()
265 }()
266 }
267
268 wg.Wait()
269 })
270 }
271}
272
273// BenchmarkPubSubMultipleChannels benchmarks subscribing to multiple channels
274func BenchmarkPubSubMultipleChannels(b *testing.B) {

Callers

nothing calls this directly

Calls 6

benchmarkClientFunction · 0.85
WaitMethod · 0.80
CloseMethod · 0.65
AddMethod · 0.65
SubscribeMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…