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
Configure and enforce max connections per user at runtime #707
Open
Justin-Kwan
wants to merge
13
commits into
pgbouncer:master
Choose a base branch
from
Justin-Kwan:justin/feature/enforce_max_user_connections
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Configure and enforce max connections per user at runtime #707
Justin-Kwan
wants to merge
13
commits into
pgbouncer:master
from
Justin-Kwan:justin/feature/enforce_max_user_connections
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Justin-Kwan
changed the title
Justin/feature/enforce max user connections
Enforce Max User Connections at Runtime
Apr 16, 2022
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
from
April 16, 2022 00:14
beffc77
to
c12bd87
Compare
Justin-Kwan
changed the title
Enforce Max User Connections at Runtime
Configure and Throttle Max User Connections at Runtime
Apr 16, 2022
Justin-Kwan
changed the title
Configure and Throttle Max User Connections at Runtime
Configure and enforce max user connections at runtime
Apr 16, 2022
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
8 times, most recently
from
April 18, 2022 18:21
f43dd22
to
2d4500f
Compare
viggy28
approved these changes
Apr 18, 2022
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
3 times, most recently
from
April 21, 2022 21:34
07248c8
to
82f9bbe
Compare
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
8 times, most recently
from
April 24, 2022 22:45
1580fd7
to
adf171c
Compare
Justin-Kwan
changed the title
Configure and enforce max user connections at runtime
Configure and enforce max connections per user at runtime
Apr 26, 2022
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
from
May 10, 2022 06:47
1cf4190
to
821b2e5
Compare
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
from
May 10, 2022 06:52
821b2e5
to
9f4e309
Compare
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
from
May 11, 2022 16:49
9f4e309
to
0b2c3f4
Compare
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
2 times, most recently
from
May 11, 2022 20:18
b48531c
to
2add413
Compare
Justin-Kwan
force-pushed
the
justin/feature/enforce_max_user_connections
branch
from
May 11, 2022 21:45
2add413
to
57b3322
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a new command to enforce max user connections at runtime. In addition to existing
max_user_connections
per user onpgbouncer.ini
file reload, PgBouncer operators can now executeSET USER <user> = 'max_user_connections=<new limit> pool_mode=<session|transaction|statement>'
to update a user's max connections across all pools that the user is in.When the
pgbouncer.ini
file is reloaded, or the above command is submitted, PgBouncer will now drop the user's connections as a reaction to these new values. PgBouncer will prioritize killing any idle and unused connections, and then kill the oldest active connections across all pools owned by the user to achieve the configured connection limit.In addition, this PR also updates the
SHOW USERS;
command to display the maximum configured connections per user to increase visibility when throttling users.In a production multi-tenant cluster, we have seen the need for PgBouncer to enforce maximum connections per user across all pools. When our upstream services (PG users) acquires too many connections while executing expensive and/or repetitive queries, this often puts strain on our Postgres primary server and starves CPU/Disk IO resources at the server. To remediate this, currently we manually constrain the user to maximum number of Postgres connections at server side via
ALTER USER "some_bad-user" WITH CONNECTION LIMIT 123;
. We've seen a clear correlation between the connection pool size (concurrency) per tenant denoted in green and database resource load denoted in yellow:Having this option in PgBouncer would be very convenient because:
SET USER ...
commandNote
This PR follows from #706 and has some overlapping commits. The previous PR should merge before this one.
cc @viggy28