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

Pool::acquire always sends a ping to the connection it returns #1743

Closed
lovasoa opened this issue Mar 10, 2022 · 6 comments · Fixed by #1901
Closed

Pool::acquire always sends a ping to the connection it returns #1743

lovasoa opened this issue Mar 10, 2022 · 6 comments · Fixed by #1901

Comments

@lovasoa
Copy link
Contributor

lovasoa commented Mar 10, 2022

Looking at my logs, it seems that sqlx sends a ping to a connection each time it is acquired from a pool, no matter how old the latest ping is. This results in a lot of unnecessary pings.

Would it be possible to add a configurable minimum delay before which connections can be acquired without ping ? So that when the application is busy, no ping is ever sent (sqlx knows that the connection is healthy because it has a recent successful request), but a ping is sent on the first request after a long period of inactivity.

@abonander
Copy link
Collaborator

You can do .test_before_acquire(false) on PoolOptions to turn off the pings on acquire.

That does mean the pool will stop pinging the connections entirely, though. The idle reaper should test connections but it doesn't.

@lovasoa
Copy link
Contributor Author

lovasoa commented Mar 10, 2022

What I would like is not to never test before acquiring, it is for sqlx to record the time of the latest successful ping or request on each connection, and to test the connection only if it is more than a few milliseconds ago.

@lovasoa
Copy link
Contributor Author

lovasoa commented Jun 17, 2022

Looking at the code, it seems that the problem is still there, isn't it ? @abonander

https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/pool/inner.rs#L363

The connection is going to be pinged again even if it had a successful interaction with the database half a millisecond ago.

@abonander
Copy link
Collaborator

It doesn't log a query every ping() call anymore and there's an example in the PoolOptions docs to implement your custom ping routine: https://docs.rs/sqlx/latest/sqlx/pool/struct.PoolOptions.html#example-custom-test_before_acquire-logic

@lovasoa
Copy link
Contributor Author

lovasoa commented Jun 17, 2022

Great, before_acquire is exactly what I needed, thank you !

@lovasoa
Copy link
Contributor Author

lovasoa commented Jun 17, 2022

Hmmm, sounds like I rejoiced too quickly. The example code in before_acquire_logic panics. I'll open a new issue.

Edit: done. #1912 (comment)

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 a pull request may close this issue.

2 participants