Skip to content

Commit

Permalink
Merge pull request #450 from go-redis/fix/remove-dial-limiter
Browse files Browse the repository at this point in the history
Remove dial limiter.
  • Loading branch information
vmihailenco committed Dec 16, 2016
2 parents b49d47e + c17f58f commit a3eed90
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 60 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions internal/pool/bench_test.go
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
39 changes: 3 additions & 36 deletions internal/pool/pool.go
Expand Up @@ -8,8 +8,6 @@ import (
"sync/atomic"
"time"

"gopkg.in/bsm/ratelimit.v1"

"gopkg.in/redis.v5/internal"
)

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions internal/pool/pool_test.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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++ {
Expand All @@ -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++ {
Expand Down
2 changes: 0 additions & 2 deletions pool_test.go
Expand Up @@ -7,7 +7,6 @@ import (
. "github.com/onsi/gomega"

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

var _ = Describe("pool", func() {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions race_test.go
Expand Up @@ -12,7 +12,6 @@ import (
. "github.com/onsi/gomega"

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

var _ = Describe("races", func() {
Expand Down Expand Up @@ -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++ {
Expand Down

0 comments on commit a3eed90

Please sign in to comment.