BenchmarkPoolGetPutWithMinIdle benchmarks pool operations with MinIdleConns
(b *testing.B)
| 98 | |
| 99 | // BenchmarkPoolGetPutWithMinIdle benchmarks pool operations with MinIdleConns |
| 100 | func 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 |
| 143 | func BenchmarkPoolConcurrentGetPut(b *testing.B) { |