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

Reduces the amount of time the get_pool operation takes #625

Merged
merged 3 commits into from
Oct 20, 2023

Conversation

zainkabani
Copy link
Contributor

@zainkabani zainkabani commented Oct 20, 2023

Couple changes to reduce impact of get_pool in the client.

The trade off with this is that clients won't get the latest query_router configs outside of a transaction, instead it'll have to wait for after the first execution, which seems like a worth while tradeoff to reduce the overall time this operation takes

Before:
image

  1. The get_pool call is currently made at the beginning for the initial handle loop, this especially in something like the extended/prepared protocol will constantly be called and not necessarily used. Moving the initialization to outside the loop, and adding the update to after we're done buffering and ready to get a connection from the pool significantly reduces the amount of times we call this function

Here's the results after this change:
image

Get pool is called less and takes less total time

  1. cloning the pool every time is expensive because it has to clone some of the different elements in the ConnectionPool struct. We can make this clone more inexpensive by wrapping those elements in an Arc so that we just have to clone the reference. This works especially well because they are things we don't mutate after initialization.

Here's the results adding this change as well
image

get_pools now takes a significantly smaller portion of time to execute ~80% reduction

The test being run is a tool that sends various selects through pgcat using the extended protocol

@zainkabani zainkabani marked this pull request as ready for review October 20, 2023 04:54
@levkk
Copy link
Contributor

levkk commented Oct 20, 2023

Really nice!

@levkk levkk merged commit d37df43 into postgresml:main Oct 20, 2023
1 check passed
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