Merge pull request #586 from go-redis/fix/pool-fast-path

pool: add fast path
This commit is contained in:
Vladimir Mihailenco 2017-06-29 13:24:08 +03:00 committed by GitHub
commit c8159532bc
1 changed files with 28 additions and 20 deletions

View File

@ -106,6 +106,9 @@ func (p *ConnPool) NewConn() (*Conn, error) {
}
func (p *ConnPool) PopFree() *Conn {
select {
case p.queue <- struct{}{}:
default:
timer := timers.Get().(*time.Timer)
timer.Reset(p.poolTimeout)
@ -120,6 +123,7 @@ func (p *ConnPool) PopFree() *Conn {
atomic.AddUint32(&p.stats.Timeouts, 1)
return nil
}
}
p.freeConnsMu.Lock()
cn := p.popFree()
@ -150,6 +154,9 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
atomic.AddUint32(&p.stats.Requests, 1)
select {
case p.queue <- struct{}{}:
default:
timer := timers.Get().(*time.Timer)
timer.Reset(p.poolTimeout)
@ -164,6 +171,7 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
atomic.AddUint32(&p.stats.Timeouts, 1)
return nil, false, ErrPoolTimeout
}
}
for {
p.freeConnsMu.Lock()