Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: increase pg pool connection idle timeout #1349

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

davenewza
Copy link
Contributor

@davenewza davenewza commented Jan 7, 2024

Increasing pg pool connection idle timeout

We're seeing about 1s - 1.5s to establish new connections for Braverly's case with their Singapore database. I cannot explain yet why it is so long, but what we can do is reduce the number of times this needs to occur.

This change increases the idle time before closing a connection in the local pool (from 10s default) to 2 minutes. Establishing a new connection on (almost) every functions query can be expensive, so this will reduce having to open connections as regularly. https://node-postgres.com/apis/pool

NOTE: We should consider setting this to 0 (i.e. never pool locally) and open and close connections with each invocation. This is because the freeze/thaw nature of lambdas can cause problems with long-lived connections - see brianc/node-postgres#2718. Once we're "fully regional" this should not be a performance problem anymore.

Although I doubt we will run into these freeze/thaw issues if idleTimeoutMillis is always shorter than the time is takes for a lambda to freeze (which is not a constant, but could be as short as several minutes, https://www.pluralsight.com/resources/blog/cloud/how-long-does-aws-lambda-keep-your-idle-functions-around-before-a-cold-start)

@davenewza davenewza changed the title perf/increase pg pool connection idletimeout perf: increase pg pool connection idle timeout Jan 7, 2024
@davenewza davenewza marked this pull request as ready for review January 7, 2024 06:23
@davenewza davenewza requested a review from a team January 7, 2024 06:23
@davenewza davenewza merged commit 0648acb into main Jan 8, 2024
10 checks passed
@davenewza davenewza deleted the perf/increase-pg-pool-connection-idletimeout branch January 8, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants