From 210e2a6fb3ee008655a7d8c699fc68539d8d20c7 Mon Sep 17 00:00:00 2001 From: Shubha Rajan Date: Wed, 29 Apr 2020 11:17:59 -0700 Subject: [PATCH] fix(cloud-sql): update unclear configuration in postgres connection sample (#1746) * updated timeout, backoff, and lifetime region tags for clarity * moved idleTimeoutMillis to timeout region tag --- cloud-sql/postgres/knex/server.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cloud-sql/postgres/knex/server.js b/cloud-sql/postgres/knex/server.js index 5b7388c855..9d944b8e5f 100644 --- a/cloud-sql/postgres/knex/server.js +++ b/cloud-sql/postgres/knex/server.js @@ -75,26 +75,27 @@ const connect = () => { // Additional connections will be established to meet this value unless the pool is full. knex.client.pool.min = 5; // [END cloud_sql_postgres_knex_limit] + // [START cloud_sql_postgres_knex_timeout] - // '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. + // 'acquireTimeoutMillis' is the number of milliseconds before a timeout occurs when acquiring a + // connection from the pool. This is slightly different from connectionTimeout, because acquiring + // a pool connection does not always involve making a new connection, and may include multiple retries. + // when making a connection + knex.client.pool.acquireTimeoutMillis = 60000; // 60 seconds + // 'createTimeoutMillis` is the maximum number of milliseconds to wait trying to establish an + // initial connection before retrying. + // After acquireTimeoutMillis has passed, a timeout exception will be thrown. knex.client.pool.createTimeoutMillis = 30000; // 30 seconds - // 'idleTimeoutMillis' is the maximum amount of time a connection can sit in the pool. Connections that - // sit idle for this many milliseconds are retried if idleTimeoutMillis is exceeded. + // 'idleTimeoutMillis' is the number of milliseconds a connection must sit idle in the pool + // and not be checked out before it is automatically closed. knex.client.pool.idleTimeoutMillis = 600000; // 10 minutes // [END cloud_sql_postgres_knex_timeout] + // [START cloud_sql_postgres_knex_backoff] + // 'knex' uses a built-in retry strategy which does not implement backoff. // 'createRetryIntervalMillis' is how long to idle after failed connection creation before trying again knex.client.pool.createRetryIntervalMillis = 200; // 0.2 seconds // [END cloud_sql_postgres_knex_backoff] - // [START cloud_sql_postgres_knex_lifetime] - // '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 minutes - // [START cloud_sql_postgres_knex_lifetime] // [END_EXCLUDE] return knex;