diff --git a/.travis.yml b/.travis.yml index 4c70460bf..41e06f836 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ matrix: - go: tip install: - - go get gopkg.in/bsm/ratelimit.v1 - go get github.com/onsi/ginkgo - go get github.com/onsi/gomega - mkdir -p $HOME/gopath/src/gopkg.in diff --git a/internal/pool/bench_test.go b/internal/pool/bench_test.go index be2c3053a..9184fe742 100644 --- a/internal/pool/bench_test.go +++ b/internal/pool/bench_test.go @@ -10,7 +10,6 @@ import ( func benchmarkPoolGetPut(b *testing.B, poolSize int) { connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour) - connPool.DialLimiter = nil b.ResetTimer() @@ -41,7 +40,6 @@ func BenchmarkPoolGetPut1000Conns(b *testing.B) { 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() diff --git a/internal/pool/pool.go b/internal/pool/pool.go index b7e8977f8..6a0e05773 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -8,8 +8,6 @@ import ( "sync/atomic" "time" - "gopkg.in/bsm/ratelimit.v1" - "gopkg.in/redis.v5/internal" ) @@ -49,9 +47,8 @@ type Pooler interface { type dialer func() (net.Conn, error) type ConnPool struct { - _dial dialer - DialLimiter *ratelimit.RateLimiter - OnClose func(*Conn) error + dial dialer + OnClose func(*Conn) error poolTimeout time.Duration idleTimeout time.Duration @@ -74,8 +71,7 @@ var _ Pooler = (*ConnPool)(nil) func NewConnPool(dial dialer, poolSize int, poolTimeout, idleTimeout, idleCheckFrequency time.Duration) *ConnPool { p := &ConnPool{ - _dial: dial, - DialLimiter: ratelimit.New(3*poolSize, time.Second), + dial: dial, poolTimeout: poolTimeout, idleTimeout: idleTimeout, @@ -90,23 +86,6 @@ func NewConnPool(dial dialer, poolSize int, poolTimeout, idleTimeout, idleCheckF return p } -func (p *ConnPool) dial() (net.Conn, error) { - if p.DialLimiter != nil && p.DialLimiter.Limit() { - err := fmt.Errorf( - "redis: you open connections too fast (last_error=%q)", - p.loadLastErr(), - ) - return nil, err - } - - cn, err := p._dial() - if err != nil { - p.storeLastErr(err.Error()) - return nil, err - } - return cn, nil -} - func (p *ConnPool) NewConn() (*Conn, error) { netConn, err := p.dial() if err != nil { @@ -292,7 +271,6 @@ func (p *ConnPool) Close() error { } func (p *ConnPool) closeConn(cn *Conn, reason error) error { - p.storeLastErr(reason.Error()) if p.OnClose != nil { _ = p.OnClose(cn) } @@ -356,17 +334,6 @@ func (p *ConnPool) reaper(frequency time.Duration) { } } -func (p *ConnPool) storeLastErr(err string) { - p.lastErr.Store(err) -} - -func (p *ConnPool) loadLastErr() string { - if v := p.lastErr.Load(); v != nil { - return v.(string) - } - return "" -} - //------------------------------------------------------------------------------ var idleCheckFrequency atomic.Value diff --git a/internal/pool/pool_test.go b/internal/pool/pool_test.go index 7ba35fd41..ece9b8f54 100644 --- a/internal/pool/pool_test.go +++ b/internal/pool/pool_test.go @@ -23,21 +23,6 @@ var _ = Describe("ConnPool", 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 - } - - _ = connPool.Remove(cn, errors.New("test")) - } - - Expect(rateErr).To(MatchError(`redis: you open connections too fast (last_error="test")`)) - }) - It("should unblock client when conn is removed", func() { // Reserve one connection. cn, _, err := connPool.Get() @@ -220,7 +205,6 @@ var _ = Describe("race", func() { It("does not happen on Get, Put, and Remove", func() { connPool = pool.NewConnPool( dummyDialer, 10, time.Minute, time.Millisecond, time.Millisecond) - connPool.DialLimiter = nil perform(C, func(id int) { for i := 0; i < N; i++ { @@ -244,7 +228,6 @@ var _ = Describe("race", func() { It("does not happen on Get and PopFree", func() { connPool = pool.NewConnPool( dummyDialer, 10, time.Minute, time.Second, time.Millisecond) - connPool.DialLimiter = nil perform(C, func(id int) { for i := 0; i < N; i++ { diff --git a/pool_test.go b/pool_test.go index 607fa463e..08760296d 100644 --- a/pool_test.go +++ b/pool_test.go @@ -7,7 +7,6 @@ import ( . "github.com/onsi/gomega" "gopkg.in/redis.v5" - "gopkg.in/redis.v5/internal/pool" ) var _ = Describe("pool", func() { @@ -80,7 +79,6 @@ var _ = Describe("pool", func() { It("respects max size on pubsub", func() { connPool := client.Pool() - connPool.(*pool.ConnPool).DialLimiter = nil perform(1000, func(id int) { pubsub, err := client.Subscribe() diff --git a/race_test.go b/race_test.go index 2f5e7b31d..34973fe12 100644 --- a/race_test.go +++ b/race_test.go @@ -12,7 +12,6 @@ import ( . "github.com/onsi/gomega" "gopkg.in/redis.v5" - "gopkg.in/redis.v5/internal/pool" ) var _ = Describe("races", func() { @@ -139,7 +138,6 @@ var _ = Describe("races", func() { It("should PubSub", func() { connPool := client.Pool() - connPool.(*pool.ConnPool).DialLimiter = nil perform(C, func(id int) { for i := 0; i < N; i++ {