示例#1
0
文件: options.go 项目: otsimo/watch
func newConnPool(opt *Options) *pool.ConnPool {
	return pool.NewConnPool(
		opt.getDialer(),
		opt.getPoolSize(),
		opt.getPoolTimeout(),
		opt.getIdleTimeout(),
		opt.getIdleCheckFrequency(),
	)
}
示例#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)
			}
		}
	})
}
示例#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)
			}
		}
	})
}
示例#4
0
文件: pool_test.go 项目: otsimo/watch
	"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
			}