redis/internal/pool/bench_test.go

77 lines
1.5 KiB
Go
Raw Normal View History

package pool_test
import (
"testing"
"time"
2017-02-18 17:42:34 +03:00
"github.com/go-redis/redis/internal/pool"
)
func benchmarkPoolGetPut(b *testing.B, poolSize int) {
connPool := pool.NewConnPool(&pool.Options{
Dialer: dummyDialer,
PoolSize: poolSize,
PoolTimeout: time.Second,
IdleTimeout: time.Hour,
IdleCheckFrequency: time.Hour,
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
2018-05-28 17:27:24 +03:00
cn, err := connPool.Get()
if err != nil {
2016-03-17 19:00:47 +03:00
b.Fatal(err)
}
2018-05-28 17:27:24 +03:00
connPool.Put(cn)
}
})
}
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(&pool.Options{
Dialer: dummyDialer,
PoolSize: poolSize,
PoolTimeout: time.Second,
IdleTimeout: time.Hour,
IdleCheckFrequency: time.Hour,
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
2018-05-28 17:27:24 +03:00
cn, err := connPool.Get()
if err != nil {
2016-03-17 19:00:47 +03:00
b.Fatal(err)
}
2018-05-28 17:27:24 +03:00
connPool.Remove(cn)
}
})
}
2016-03-17 19:00:47 +03:00
func BenchmarkPoolGetRemove10Conns(b *testing.B) {
benchmarkPoolGetRemove(b, 10)
}
2016-03-17 19:00:47 +03:00
func BenchmarkPoolGetRemove100Conns(b *testing.B) {
benchmarkPoolGetRemove(b, 100)
}
2016-03-17 19:00:47 +03:00
func BenchmarkPoolGetRemove1000Conns(b *testing.B) {
benchmarkPoolGetRemove(b, 1000)
}