Pārlūkot izejas kodu

try to fill the connection pool more often

Chris Bannister 10 gadi atpakaļ
vecāks
revīzija
023d93bc08
1 mainītis faili ar 8 papildinājumiem un 4 dzēšanām
  1. 8 4
      connectionpool.go

+ 8 - 4
connectionpool.go

@@ -222,6 +222,7 @@ func (p *policyConnPool) addHost(host *HostInfo) {
 
 
 	pool, ok := p.hostConnPools[host.Peer()]
 	pool, ok := p.hostConnPools[host.Peer()]
 	if ok {
 	if ok {
+		go pool.fill()
 		return
 		return
 	}
 	}
 
 
@@ -312,13 +313,16 @@ func (pool *hostConnPool) Pick(qry *Query) *Conn {
 		return nil
 		return nil
 	}
 	}
 
 
-	empty := len(pool.conns) == 0
+	size := len(pool.conns)
 	pool.mu.RUnlock()
 	pool.mu.RUnlock()
 
 
-	if empty {
-		// try to fill the empty pool
+	if size < pool.size {
+		// try to fill the pool
 		go pool.fill()
 		go pool.fill()
-		return nil
+
+		if size == 0 {
+			return nil
+		}
 	}
 	}
 
 
 	return pool.policy.Pick(qry)
 	return pool.policy.Pick(qry)