-
Notifications
You must be signed in to change notification settings - Fork 121
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
Memory Leak when using prepare_cached #281
Comments
A prepared statement uses memory on both the client and the database itself. https://www.postgresql.org/docs/current/sql-prepare.html
The built-in statement cache of
|
I just opened an issue regarding the addition of an automatic cache clean-up: I'd be very interested in your insights. |
@bikeshedder thank you for the information and the proposed enhancement. I'll review and let you know if I have any thoughts\comments! |
I want to hone in one specific sentence from your response to make sure I understand correctly.
When you say "after dropping the connection", do you mean when the connection is closed altogether? Or do you simply mean when it's returned to the database Pool as an idle connection for other sessions to use? My understanding is that, when using a Recycling Mode other than something like |
The statement cache does not get cleared regardless of the recycling method. https://docs.rs/deadpool-postgres/latest/deadpool_postgres/enum.RecyclingMethod.html#variant.Clean
When you drop the connection (aka return it to the pool) the statement cache is kept for the next user of the connection.
That's correct. Unless you explicitly call the |
I'm closing this as invalid. There is no memory leak in Issue #282 tracks the feature of automatically removing unused statements from the cache. |
Hi,
First, thank you for the excellent crate! We've reliably used this for all of our Rust projects.
A few weeks ago, one of our applications saw a complete drain of our freeable memory. After digging in, we found that the problem subsided after creating a background job using tokio::spawn that would take our Database Pools and clear out all the Statement Caches. After digging even further, we found that when we switched from preparing our statements with
prepare_cached
toprepare
, our memory stabilized and no longer showed the same leaking behavior.I have included a screenshot from DataDog to show the difference in behavior.
On the screenshot, when you see the memory jump up, we had an application restart so that we could recover the used memory. If we had let it continue, the memory would have bottomed out.
I'm looking for a couple of things:
prepare_cached
andprepare
. Both seem to indicate that they're generating Prepared Statements, so I'm not quite sure why you'd use one over the other.Dependencies used:
Also note that we experienced this problem before updating to deadpool v0.10. We made the update last week in seeing if this update addressed the issue, to no avail.
If there is any more background or information I can provide to help, please let me know.
Thanks!
The text was updated successfully, but these errors were encountered: