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

Function BenchmarkPoolGetPutWithMinIdle

pool_pubsub_bench_test.go:100–140  ·  view source on GitHub ↗

BenchmarkPoolGetPutWithMinIdle benchmarks pool operations with MinIdleConns

(b *testing.B)

Source from the content-addressed store, hash-verified

98
99// BenchmarkPoolGetPutWithMinIdle benchmarks pool operations with MinIdleConns
100func BenchmarkPoolGetPutWithMinIdle(b *testing.B) {
101 ctx := context.Background()
102
103 configs := []struct {
104 poolSize int
105 minIdleConns int
106 }{
107 {8, 2},
108 {16, 4},
109 {32, 8},
110 {64, 16},
111 }
112
113 for _, config := range configs {
114 b.Run(fmt.Sprintf("Pool_%d_MinIdle_%d", config.poolSize, config.minIdleConns), func(b *testing.B) {
115 connPool := pool.NewConnPool(&pool.Options{
116 Dialer: dummyDialer,
117 PoolSize: int32(config.poolSize),
118 MaxConcurrentDials: config.poolSize,
119 MinIdleConns: int32(config.minIdleConns),
120 PoolTimeout: time.Second,
121 DialTimeout: time.Second,
122 ConnMaxIdleTime: time.Hour,
123 })
124 defer connPool.Close()
125
126 b.ResetTimer()
127 b.ReportAllocs()
128
129 b.RunParallel(func(pb *testing.PB) {
130 for pb.Next() {
131 cn, err := connPool.Get(ctx)
132 if err != nil {
133 b.Fatal(err)
134 }
135 connPool.Put(ctx, cn)
136 }
137 })
138 })
139 }
140}
141
142// BenchmarkPoolConcurrentGetPut benchmarks pool under high concurrency
143func BenchmarkPoolConcurrentGetPut(b *testing.B) {

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