| 19 | } |
| 20 | |
| 21 | func BenchmarkPoolGetPut(b *testing.B) { |
| 22 | ctx := context.Background() |
| 23 | benchmarks := []poolGetPutBenchmark{ |
| 24 | {1}, |
| 25 | {2}, |
| 26 | {8}, |
| 27 | {32}, |
| 28 | {64}, |
| 29 | {128}, |
| 30 | } |
| 31 | for _, bm := range benchmarks { |
| 32 | b.Run(bm.String(), func(b *testing.B) { |
| 33 | connPool := pool.NewConnPool(&pool.Options{ |
| 34 | Dialer: dummyDialer, |
| 35 | PoolSize: int32(bm.poolSize), |
| 36 | MaxConcurrentDials: bm.poolSize, |
| 37 | PoolTimeout: time.Second, |
| 38 | DialTimeout: 1 * time.Second, |
| 39 | ConnMaxIdleTime: time.Hour, |
| 40 | }) |
| 41 | |
| 42 | b.ResetTimer() |
| 43 | |
| 44 | b.RunParallel(func(pb *testing.PB) { |
| 45 | for pb.Next() { |
| 46 | cn, err := connPool.Get(ctx) |
| 47 | if err != nil { |
| 48 | b.Fatal(err) |
| 49 | } |
| 50 | connPool.Put(ctx, cn) |
| 51 | } |
| 52 | }) |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | type poolGetRemoveBenchmark struct { |
| 58 | poolSize int |