-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
fix memory leaks #1350
fix memory leaks #1350
Conversation
I also added a fix to While this variant makes tests green, there could be other types of streams that we would not want to destroy to avoid segfaults. |
lol, my push got blocked and we did the same exact change... :D |
I think this is good to go (we may have to just run it on a few projects to see if there are any new issues)? Are there any objections to merging as-is? @dunglas / @AlliBalliBaba |
This definitely also fixes the slowdown which probably comes from mapping over an increasingly big This does not fix the reason why big MySQL queries are so much slower than big PostgreSQL queries though. After building and testing this branch, it's the same for worker and non-worker mode. It could be related to the ZTS TODO you mentioned. Might also be worth testing if the same thing happens when using the native MySQL driver. |
This probably is semi-safe to merge. It would be nice to have some tests with resources that persist across requests. |
I added a test, feel free to add more. Not sure what other types of streams exist. |
Impressive debugging session and collaboration! Thank to both of you!! |
That and GC pressure as well (more often GC means less time doing useful stuff). |
Co-authored-by: Kévin Dunglas <[email protected]>
Co-authored-by: Kévin Dunglas <[email protected]>
Does disabling
There may be others, but I don't remember them off the top of my head and I can't remember if frameworks set this up for you. |
Now that you mentioned ini settings, I tried So I suspect this is due to a lock in |
Haven't tested it, but my guess is it could be these lines that create a lock on every single database row read So the slowdown gets noticeable as soon as many CPU cores are all busy only reading lines coming from MySQL. |
Nice find! |
This gets tricky and a route a spent quite a bit of time on yesterday but wasn't sure we needed to. We have no idea if a resource should be shared between requests or only in that request. We need to hook into streams (set up a noop filter to configure a generational GC of sorts). If a resource hasn't been used for a few requests, or is closed, we remove it. If it is hot, we remove it from our checks. This isn't 100% perfect, but can be reasonably correct. Alternatively, we hook into the AST (similar to opcache) and keep track of where the resource is created (global scope or not; and even this will be super complicated to track via realtime escape analysis). This is probably the "more correct" implementation but waaay more complicated -- and I'm not 100% sure it will work. Another approach, the one I started implementing, is much simpler than either option: simply get the count of the resource list at the start of the request and only consider those that have a higher index at the end of the request. This is probably the least correct solution but is probably the simplest. |
Hmm I'd usually expect it to be save to remove all unreferenced temporary streams. I'll also try if doing this at the start of the request instead of at the end will get rid of the error. |
There's a small ~800 byte memory leak on worker shutdown. This frees the request context once the thread is shut down.
This also addresses a memory leak by resources where we now delete any un-referenced resources after a request.
#1321