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

Function BenchmarkPoolConcurrentGetPut

pool_pubsub_bench_test.go:143–177  ·  view source on GitHub ↗

BenchmarkPoolConcurrentGetPut benchmarks pool under high concurrency

(b *testing.B)

Source from the content-addressed store, hash-verified

141
142// BenchmarkPoolConcurrentGetPut benchmarks pool under high concurrency
143func BenchmarkPoolConcurrentGetPut(b *testing.B) {
144 ctx := context.Background()
145
146 connPool := pool.NewConnPool(&pool.Options{
147 Dialer: dummyDialer,
148 PoolSize: int32(32),
149 MaxConcurrentDials: 32,
150 PoolTimeout: time.Second,
151 DialTimeout: time.Second,
152 ConnMaxIdleTime: time.Hour,
153 MinIdleConns: int32(0),
154 })
155 defer connPool.Close()
156
157 b.ResetTimer()
158 b.ReportAllocs()
159
160 // Test with different levels of concurrency
161 concurrencyLevels := []int{1, 2, 4, 8, 16, 32, 64}
162
163 for _, concurrency := range concurrencyLevels {
164 b.Run(fmt.Sprintf("Concurrency_%d", concurrency), func(b *testing.B) {
165 b.SetParallelism(concurrency)
166 b.RunParallel(func(pb *testing.PB) {
167 for pb.Next() {
168 cn, err := connPool.Get(ctx)
169 if err != nil {
170 b.Fatal(err)
171 }
172 connPool.Put(ctx, cn)
173 }
174 })
175 })
176 }
177}
178
179// =============================================================================
180// PUBSUB BENCHMARKS

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
GetMethod · 0.95
PutMethod · 0.95
NewConnPoolFunction · 0.92
NextMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected