BenchmarkPoolConcurrentGetPut benchmarks pool under high concurrency
(b *testing.B)
| 141 | |
| 142 | // BenchmarkPoolConcurrentGetPut benchmarks pool under high concurrency |
| 143 | func 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 |