Skip to content

Commit

Permalink
fix(cloud-sql): update unclear configuration in postgres connection s…
Browse files Browse the repository at this point in the history
…ample (#1746)

* updated timeout, backoff, and lifetime region tags for clarity

* moved idleTimeoutMillis to timeout region tag
  • Loading branch information
shubha-rajan authored Apr 29, 2020
1 parent da03d9b commit 210e2a6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions cloud-sql/postgres/knex/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 210e2a6

Please sign in to comment.