2016-03-12 13:38:52 +03:00
|
|
|
package pool_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-04-09 13:27:16 +03:00
|
|
|
"gopkg.in/redis.v4/internal/pool"
|
2016-03-12 13:38:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func benchmarkPoolGetPut(b *testing.B, poolSize int) {
|
2016-03-17 19:00:47 +03:00
|
|
|
connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour)
|
|
|
|
connPool.DialLimiter = nil
|
2016-03-12 13:38:52 +03:00
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2016-09-29 15:07:04 +03:00
|
|
|
cn, _, err := connPool.Get()
|
2016-03-12 13:38:52 +03:00
|
|
|
if err != nil {
|
2016-03-17 19:00:47 +03:00
|
|
|
b.Fatal(err)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|
2016-03-17 19:00:47 +03:00
|
|
|
if err = connPool.Put(cn); err != nil {
|
|
|
|
b.Fatal(err)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPoolGetPut10Conns(b *testing.B) {
|
|
|
|
benchmarkPoolGetPut(b, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPoolGetPut100Conns(b *testing.B) {
|
|
|
|
benchmarkPoolGetPut(b, 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPoolGetPut1000Conns(b *testing.B) {
|
|
|
|
benchmarkPoolGetPut(b, 1000)
|
|
|
|
}
|
|
|
|
|
2016-03-17 19:00:47 +03:00
|
|
|
func benchmarkPoolGetRemove(b *testing.B, poolSize int) {
|
|
|
|
connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour)
|
|
|
|
connPool.DialLimiter = nil
|
2016-03-12 13:38:52 +03:00
|
|
|
removeReason := errors.New("benchmark")
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2016-09-29 15:07:04 +03:00
|
|
|
cn, _, err := connPool.Get()
|
2016-03-12 13:38:52 +03:00
|
|
|
if err != nil {
|
2016-03-17 19:00:47 +03:00
|
|
|
b.Fatal(err)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|
2016-03-17 19:00:47 +03:00
|
|
|
if err := connPool.Remove(cn, removeReason); err != nil {
|
|
|
|
b.Fatal(err)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-17 19:00:47 +03:00
|
|
|
func BenchmarkPoolGetRemove10Conns(b *testing.B) {
|
|
|
|
benchmarkPoolGetRemove(b, 10)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|
|
|
|
|
2016-03-17 19:00:47 +03:00
|
|
|
func BenchmarkPoolGetRemove100Conns(b *testing.B) {
|
|
|
|
benchmarkPoolGetRemove(b, 100)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|
|
|
|
|
2016-03-17 19:00:47 +03:00
|
|
|
func BenchmarkPoolGetRemove1000Conns(b *testing.B) {
|
|
|
|
benchmarkPoolGetRemove(b, 1000)
|
2016-03-12 13:38:52 +03:00
|
|
|
}
|