Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2131

Create new connections immediately when connection pool size falls below minPoolSize

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Documentation
    • None

      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().

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: