forked from mirror/redis
pool: add fast path
This commit is contained in:
parent
09f8a1b82b
commit
0a965c5d70
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue