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

Update client varcache with canonical values from server #879

Merged

Conversation

JelteF
Copy link
Member

@JelteF JelteF commented Jul 3, 2023

Since PG14, Postgres doesn't send ParameterStatus packets anymore when a
setting has not actually changed. This could cause the client varcache
and server varcache to become out of sync. Which then in turn resulted
in unnecessary SET commands to be sent to the server.

Fixes #776

JelteF added a commit to JelteF/pgjdbc that referenced this pull request Jul 3, 2023
This makes caching variable caching with PgBouncer more efficient, because now the client is setting the same values that the server reports.

See these PgBouncer issues/PRs for details:
pgbouncer/pgbouncer#776
pgbouncer/pgbouncer#879
@JelteF JelteF force-pushed the replace-client-vars-with-canonical-version branch from 2b6d125 to 418f48e Compare July 3, 2023 15:48
davecramer pushed a commit to pgjdbc/pgjdbc that referenced this pull request Jul 4, 2023
This makes caching variable caching with PgBouncer more efficient, because now the client is setting the same values that the server reports.

See these PgBouncer issues/PRs for details:
pgbouncer/pgbouncer#776
pgbouncer/pgbouncer#879
@JelteF JelteF force-pushed the replace-client-vars-with-canonical-version branch from 418f48e to c069e6e Compare July 4, 2023 11:53
@JelteF JelteF force-pushed the replace-client-vars-with-canonical-version branch from c069e6e to 889fb5e Compare July 27, 2023 08:44
@JelteF JelteF requested a review from eulerto July 27, 2023 08:45
@JelteF JelteF force-pushed the replace-client-vars-with-canonical-version branch 2 times, most recently from 0ffae79 to b8aa11b Compare August 10, 2023 20:22
@JelteF
Copy link
Member Author

JelteF commented Aug 11, 2023

I did some basic benchmarks against PG15 using:

PGOPTIONS='-c datestyle=ISO' pgbench -p 6432 -T 20 -P 1 --select-only 'host=localhost port=6432'

And the TPS is as follows on my machine:

  • master: 1970
  • this PR: 2803 (42% faster)

If I introduce 10ms of artificial latency between PgBouncer and Postgres then it goes from:

  • master: 45
  • this PR: 90 (100% faster)

Since PG14, Postgres doesn't send ParameterStatus packets anymore when a
setting has not actually changed. This could cause the client varcache
and server varcache to become out of sync. Which then in turn resulted
in unnecessary `SET` commands to be sent to the server.

Fixes pgbouncer#776
@JelteF JelteF force-pushed the replace-client-vars-with-canonical-version branch from b8aa11b to 2c032fa Compare August 16, 2023 14:26
@emelsimsek
Copy link
Contributor

emelsimsek commented Dec 29, 2023

I tested this fix with PG 16.0. It looks good from functional perspective.

The downside is the overhead of checking the startup parameters against the canonical ones for every new client connection even if such clients might be in minority. But I am not sure if this feature should be made opt-in.

Since the size of varcache we need to iterate for every new connection is so small, the perf hit should be negligible. So, IMO, it does not worth it to introduce a yet another config param.

@JelteF JelteF merged commit 894caec into pgbouncer:master Dec 30, 2023
23 checks passed
@JelteF JelteF deleted the replace-client-vars-with-canonical-version branch December 30, 2023 12:29
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.

Queries SET DateStyle='ISO'; appeared in every transaction after migration to pg 14
2 participants