Default value of MaxIdleConnections in net2.ConnectionPool is extremely slow
- Dominant language
- Go
- Stars
- 4.2k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
Benchmark results:
```
Fake dealer:
BenchmarkGetConnection-16 1492227 803.2 ns/op
BenchmarkGetConnectionMaxIdle-16 1888982 631.4 ns/op
Real dealer:
BenchmarkGetConnection-16 9052 113356 ns/op
BenchmarkGetConnectionMaxIdle-16 1901071 626.9 ns/op
```
Code example:
```
func BenchmarkGetConnection(b *testing.B) {
// dialer := fakeDialer{}
// mockClock := time2.MockClock{}
options := ConnectionOptions{
// MaxIdleConnections: 1,
// Dial: dialer.FakeDial,
// NowFunc: mockClock.Now,
}
pool := NewSimpleConnectionPool(options)
pool.Register("tcp", "localhost:11211")
b.ResetTimer();
for i := 0; i < b.N; i++ {
c, err := pool.Get("tcp", "localhost:6379")
if err != nil {
b.Fatal(err)
}
c.ReleaseConnection()
}
}
func BenchmarkGetConnectionMaxIdle(b *testing.B) {
// dialer := fakeDialer{}
// mockClock := time2.MockClock{}
options := ConnectionOptions{
MaxIdleConnections: 1,
// Dial: dialer.FakeDial,
// NowFunc: mockClock.Now,
}
pool := NewSimpleConnectionPool(options)
pool.Register("tcp", "localhost:11211")
b.ResetTimer();
for i := 0; i < b.N; i++ {
c, err := pool.Get("tcp", "localhost:6379")
if err != nil {
b.Fatal(err)
}
c.ReleaseConnection()
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.