| 63 | } |
| 64 | |
| 65 | func BenchmarkPoolGetRemove(b *testing.B) { |
| 66 | ctx := context.Background() |
| 67 | benchmarks := []poolGetRemoveBenchmark{ |
| 68 | {1}, |
| 69 | {2}, |
| 70 | {8}, |
| 71 | {32}, |
| 72 | {64}, |
| 73 | {128}, |
| 74 | } |
| 75 | |
| 76 | for _, bm := range benchmarks { |
| 77 | b.Run(bm.String(), func(b *testing.B) { |
| 78 | connPool := pool.NewConnPool(&pool.Options{ |
| 79 | Dialer: dummyDialer, |
| 80 | PoolSize: int32(bm.poolSize), |
| 81 | MaxConcurrentDials: bm.poolSize, |
| 82 | PoolTimeout: time.Second, |
| 83 | DialTimeout: 1 * time.Second, |
| 84 | ConnMaxIdleTime: time.Hour, |
| 85 | }) |
| 86 | |
| 87 | b.ResetTimer() |
| 88 | rmvErr := errors.New("Bench test remove") |
| 89 | b.RunParallel(func(pb *testing.PB) { |
| 90 | for pb.Next() { |
| 91 | cn, err := connPool.Get(ctx) |
| 92 | if err != nil { |
| 93 | b.Fatal(err) |
| 94 | } |
| 95 | connPool.Remove(ctx, cn, rmvErr) |
| 96 | } |
| 97 | }) |
| 98 | }) |
| 99 | } |
| 100 | } |