============================================================================= POOL BENCHMARKS ============================================================================= BenchmarkPoolGetPut benchmarks the core pool Get/Put operations
(b *testing.B)
| 63 | |
| 64 | // BenchmarkPoolGetPut benchmarks the core pool Get/Put operations |
| 65 | func BenchmarkPoolGetPut(b *testing.B) { |
| 66 | ctx := context.Background() |
| 67 | |
| 68 | poolSizes := []int{1, 2, 4, 8, 16, 32, 64, 128} |
| 69 | |
| 70 | for _, poolSize := range poolSizes { |
| 71 | b.Run(fmt.Sprintf("PoolSize_%d", poolSize), func(b *testing.B) { |
| 72 | connPool := pool.NewConnPool(&pool.Options{ |
| 73 | Dialer: dummyDialer, |
| 74 | PoolSize: int32(poolSize), |
| 75 | MaxConcurrentDials: poolSize, |
| 76 | PoolTimeout: time.Second, |
| 77 | DialTimeout: time.Second, |
| 78 | ConnMaxIdleTime: time.Hour, |
| 79 | MinIdleConns: int32(0), // Start with no idle connections |
| 80 | }) |
| 81 | defer connPool.Close() |
| 82 | |
| 83 | b.ResetTimer() |
| 84 | b.ReportAllocs() |
| 85 | |
| 86 | b.RunParallel(func(pb *testing.PB) { |
| 87 | for pb.Next() { |
| 88 | cn, err := connPool.Get(ctx) |
| 89 | if err != nil { |
| 90 | b.Fatal(err) |
| 91 | } |
| 92 | connPool.Put(ctx, cn) |
| 93 | } |
| 94 | }) |
| 95 | }) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // BenchmarkPoolGetPutWithMinIdle benchmarks pool operations with MinIdleConns |
| 100 | func BenchmarkPoolGetPutWithMinIdle(b *testing.B) { |