pool: add fast path

This commit is contained in:
Vladimir Mihailenco 2017-06-29 12:54:49 +03:00
parent 09f8a1b82b
commit 0a965c5d70
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()