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(pg-pool): optimize client retrieval from pool by prioritizing prepared client #3398

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

cesco69
Copy link
Contributor

@cesco69 cesco69 commented Mar 4, 2025

see #3397

Instead of retrieving the first available client from the pool, check if there is a free client that already has cached prepared statements. This could improve performance by reducing the need to re-prepare statements on different clients.

@cesco69 cesco69 changed the title perf(pg-pool): optimize client retrieval from pool by prioritizing prepared client [POC] perf(pg-pool): optimize client retrieval from pool by prioritizing prepared client Mar 4, 2025
@cesco69 cesco69 changed the title [POC] perf(pg-pool): optimize client retrieval from pool by prioritizing prepared client perf(pg-pool): optimize client retrieval from pool by prioritizing prepared client Mar 4, 2025
Copy link
Collaborator

@charmander charmander left a comment

Choose a reason for hiding this comment

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

Needs tests.

@cesco69

This comment was marked as resolved.

@cesco69 cesco69 requested a review from charmander March 5, 2025 09:27
@brianc
Copy link
Owner

brianc commented Mar 10, 2025

I'm not convinced this is a fair test. In fact, I should check that the query was executed with the same client, but how can I tell if it's the same client?

You can call pg_backend_pid() in a query - that should return the connection ID which will certainly be the same across queries on the same client.

@cesco69
Copy link
Contributor Author

cesco69 commented Mar 11, 2025

I'm not convinced this is a fair test. In fact, I should check that the query was executed with the same client, but how can I tell if it's the same client?

You can call pg_backend_pid() in a query - that should return the connection ID which will certainly be the same across queries on the same client.

Thanks! done with 20e7fa2

cesco69 added a commit to cesco69/DefinitelyTyped that referenced this pull request Mar 11, 2025
Merge this PR only if this PR brianc/node-postgres#3398 is merged and released
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.

3 participants