-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
I'm coming from the GCloud Documentation's Managing database connections page about PostgreSQL and Node.js while trying to diagnose connection issues with a live Cloud SQL database.
The section on how to configure the Knex Client pool left me wondering in some places, however:
// 'createRetryIntervalMillis' is how long to idle after failed connection creation before trying again
knex.client.pool.createRetryIntervalMillis = 200; // 0.2 secondsThe explanation recommends implementing an exponential backoff, yet here we set a flat value. Does this mean that Knex cannot be configured to do an exponential backoff when acquiring connections?
Right below it, we have:
// 'acquireTimeoutMillis' is the maximum number of milliseconds to wait for a connection checkout.
// Any attempt to retrieve a connection from this pool that exceeds the set limit will throw an
// SQLException.
knex.client.pool.createTimeoutMillis = 30000; // 30 secondsThe comment describes acquireTimeoutMillis, yet in the code the createTimeoutMillis is set. Which one is right here? Does it make a difference, and if so, what is the difference?
Below, the code then actually sets acquireTimeoutMillis:
// 'acquireTimeoutMillis' is the maximum possible lifetime of a connection in the pool. Connections that
// live longer than this many milliseconds will be closed and reestablished between uses. This
// value should be several minutes shorter than the database's timeout value to avoid unexpected
// terminations.
knex.client.pool.acquireTimeoutMillis = 600000; // 10 minutesacquireTimeoutMillis really does not sound like a "total lifetime limit", and indeed tarn.js (where the Pool implementation from knex.js is imported from) describes it like this in their documentation:
// acquire promises are rejected after this many milliseconds
// if a resource cannot be acquired
acquireTimeoutMillis: 30000,What configuration option would actually give the described "total lifetime" functionality?
The relevant code pieces are all from cloud-sql/postgres/knex/server.js.
Could someone who is more familiar with the libraries and mechanisms at work here please look over the documentation and the code that goes with it?
Thank you!