Skip to content

Commit

Permalink
try to fill the connection pool more often
Browse files Browse the repository at this point in the history
  • Loading branch information
Zariel committed Dec 25, 2015
1 parent a278050 commit 023d93b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions connectionpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (p *policyConnPool) addHost(host *HostInfo) {

pool, ok := p.hostConnPools[host.Peer()]
if ok {
go pool.fill()
return
}

Expand Down Expand Up @@ -312,13 +313,16 @@ func (pool *hostConnPool) Pick(qry *Query) *Conn {
return nil
}

empty := len(pool.conns) == 0
size := len(pool.conns)
pool.mu.RUnlock()

if empty {
// try to fill the empty pool
if size < pool.size {
// try to fill the pool
go pool.fill()
return nil

if size == 0 {
return nil
}
}

return pool.policy.Pick(qry)
Expand Down

0 comments on commit 023d93b

Please sign in to comment.