Have PgExecutor intelligently share connections - #3192
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: e8709d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
benjie
commented
Sep 25, 2026
benjie
left a comment
Member
Author
There was a problem hiding this comment.
I've reviewed the source and am happy with it. Still need to review the tests and make sure there's enough tests (in particular our tests currently run everything through a single client, we really need to test multiclient).
benjie
marked this pull request as ready for review
September 25, 2026 16:21
benjie
enabled auto-merge
September 25, 2026 16:33
benjie
disabled auto-merge
September 25, 2026 16:37
…through the same connection, reducing the overhead from multiple transaction handshakes and making better use of prepared statements and similar optimizations. Reduces both parallelism and overhead, hopefully netting an overall performance win with some potential per-request latency trade-offs.
This file contains hidden or 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
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
Previously each PgSelectStep would effectively grab its own
withPgClientand execute the query and return the results, releasing the client. This meant each step had thebegin; select set_config(...); ...; commit;overhead - 4 DB roundtrips per step. With PostGraphile's inlining this was generally reasonably efficient because you'd normally only have one or two actual fetch steps; but if you have queries with a lot of root fields or otherwise requiring many PgSelectStep the cost of these many clients can outweigh the gains of the parallelism V5's model enables.To solve this, PgExecutor will now intelligently distribute queries across connections: similar queries will go to the same connection so that they can make use of shared prepared statements and caches, different queries will spread across multiple clients (default: 3) to enable the benefits of parallelism whilst limiting maximum client consumption from the pool.
Performance impact
Max PG client parallelism is reduced:
Security impact
Reduces client exhaustion by capping the number of database clients that a particular request will use for Pg{Select,Union}Step.
Checklist
yarn lint:fixpasses.yarn testpasses.RELEASE_NOTES.mdfile (if one exists).