Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions cloud-sql/postgres/knex/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,30 @@ 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.
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]
// '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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other PR - similar arguments are in different places for other samples. Can we move this into connection count and see if there is a "max lifetime" parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a max lifetime parameter (knex uses the same underlying pool implementation as mssql) so we'll probably have to leave this sample blank like in the mysql sample.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM - make sure when we update the "Connecting to Cloud SQL" page we include a similar line for SQL Server.

// [END cloud_sql_postgres_knex_lifetime]

// [END_EXCLUDE]
return knex;
Expand Down