[GODRIVER-2131] Create new connections immediately when connection pool size falls below minPoolSize Created: 17/Aug/21  Updated: 30/Mar/22

Status: Backlog
Project: Go Driver
Component/s: Documentation
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

As described in the CMAP specification:
> If minPoolSize is set, the Connection Pool MUST have at least minPoolSize total Connections while it is "ready".

Currently, the Go driver waits for the background maintenance goroutine interval of 1 minute (or 10 seconds as proposed as part of GODRIVER-2038), not immediately when the pool size is below minPoolSize. Additionally, the current Go driver doesn't implement the "paused" or "ready" states.

Instead of waiting for the background maintenance goroutine interval to maintain minPoolSize, trigger a function or goroutine to create new connections immediately when pool size < minPoolSize.

Proposed implementation based on the current logic in PR 716:

  1. Add a new condition to condition() in createConnections() that allows a new connection to be created if there is a waiting checkOut() or the pool size is less than minPoolSize. E.g.:

    condition := func() bool {
    	checkOutWaiting := p.newConnWait.len() > 0
    	belowMinPoolSize := p.minSize > 0 && uint64(len(p.conns)) < p.minSize
    	poolHasSpace := p.maxSize == 0 || uint64(len(p.conns)) < p.maxSize
    	cancelled := ctx.Err() != nil
    	return ((checkOutWaiting || belowMinPoolSize) && poolHasSpace) || cancelled
    }
    

  2. Remove nil check from p.newConnWait.popFront() and allow w to be nil. Handle any cases where the current code expects w to never be nil.
  3. Remove minPoolSize logic from maintain().

Generated at Thu Feb 08 08:37:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.