Ejemplo n.º 1
0
func newConnPool(opt *Options) *pool.ConnPool {
	return pool.NewConnPool(
		opt.getDialer(),
		opt.getPoolSize(),
		opt.getPoolTimeout(),
		opt.getIdleTimeout(),
		opt.getIdleCheckFrequency(),
	)
}
Ejemplo n.º 2
0
func benchmarkPoolGetPut(b *testing.B, poolSize int) {
	connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour)
	connPool.DialLimiter = nil

	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			cn, err := connPool.Get()
			if err != nil {
				b.Fatal(err)
			}
			if err = connPool.Put(cn); err != nil {
				b.Fatal(err)
			}
		}
	})
}
Ejemplo n.º 3
0
func benchmarkPoolGetRemove(b *testing.B, poolSize int) {
	connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour)
	connPool.DialLimiter = nil
	removeReason := errors.New("benchmark")

	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			cn, err := connPool.Get()
			if err != nil {
				b.Fatal(err)
			}
			if err := connPool.Remove(cn, removeReason); err != nil {
				b.Fatal(err)
			}
		}
	})
}
Ejemplo n.º 4
0
	"errors"
	"net"
	"testing"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"gopkg.in/redis.v3/internal/pool"
)

var _ = Describe("ConnPool", func() {
	var connPool *pool.ConnPool

	BeforeEach(func() {
		connPool = pool.NewConnPool(
			dummyDialer, 10, time.Hour, time.Millisecond, time.Millisecond)
	})

	AfterEach(func() {
		connPool.Close()
	})

	It("rate limits dial", func() {
		var rateErr error
		for i := 0; i < 1000; i++ {
			cn, err := connPool.Get()
			if err != nil {
				rateErr = err
				break
			}