-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
PostgresClient performance decrease when executing the same queries consecutively #511
Comments
An additional observation is that is I wait 30 seconds or a minute between running the queries then the performance seems to remain at 5.2 seconds. This surely is a sign that something is being cleaned up during that time. Anyone have any suggestions as to how to 'reset' things so that the performance of queries on a new client remain constant. Perhaps something in the connection pool that needs to be reset so it doesn't get reused ? |
@duncangroenewald Can we have a reproducible example? Does it need specific queries or does it happen with any simple query? |
@MahdiBM - I will try and create an example to reproduce the issue. The queries are all simple single table queries, however there are a lot of them because each execution is fetching a heirarchy that is about 10 levels deep with about 2000 lowest level nodes. |
Here is an example of the performance degradation that we are seeing. I created a test application to do this and see the same issue as with the production application. This is testing against the same database. The m: value is the number of lowest level nodes fetched for each code. Typically the higher number would mean slightly slower read time. Bearing in mind the m value is 4 levels down in the hierarchy. However if you take the example of L025 with a fetch time of 0.5 seconds for m:30 nodes and later on M005 m:35 has a fetch time of 3.5 seconds. However run the M005 query standalone and it returns in only 0.6 seconds. In fact just wait a minute or so and then run the M005 query without even restarting the whole application and it returns in the same 0.6s. L002 (m:95) (elapsed: 1.4s, lap: 1.4s seconds) |
After some more testing I find I can get a dramatic improvement in performance consistency by setting the following:
The default keepAliceBehavior seems to have a significant negative impact on performance. L002 (m:95) (elapsed: 1.2s, lap: 1.2s seconds) |
How many concurrent requests do you run, with how many connections? |
Describe the issue
When running the same fairly complex set of queries (using the same client ) performance in each subsequence execution slows down - e.g first time 5.2 seconds, next time 5.6, next 6.0, etc. and it tends to keep climbing to over 8 seconds and probably more - I stopped testing.
Vapor version
postgres-nio 1.22.1
Operating system and version
macOS 14.6.1
Swift version
5.10.0
Steps to reproduce
A little tricky to reproduce given the number of queries in each execution run.
Restarting the client application seems to always get performance back to 5.2 seconds. Is there some cleanup necessary when using PostgresClient. Note that each execution creates a new PostgresClient but all the queries within the execution run use the same client.
Outcome
I would expect to see identical performance in each subsequent execution run - or at least within 0.1 seconds since the performance on restarting the application is nearly identical the first time the execution is run.
Additional notes
Not running Vapor - just using the PostgresClient from a macOS client application
The text was updated successfully, but these errors were encountered: