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
run regular GC if compact not available #2228
Conversation
I've been thinking about this. See nakayoshi_fork. I think maybe we should:
This will introduce a lag time before forking, maybe up to 1-2 seconds. I'm not sure if that amount of lag would be acceptable for everyone so we may need to put the whole thing behind a config flag. |
The "3 times" is very important here because you're trying to promote all existing objects to the old generation. I'm actually not sure if it would be better to compact before or after that, because I don't know how generations interaction w/compaction. |
If you try combinations of GC.start/GC.compact ordering, and test my thesis that 3 runs is better than 1, and track latency of all these options and report back, that would be 🙇 . Maybe test against rubygems.org or another decently large open source app. |
fascinating, I didn't know that multiple runs of GC.start could make a difference. I guess ruby GC makes some sort of time/value compromise and doesn't always do the best it can? in a test just now with my rails app, I set cache_classes and eager_load to true, and put started at 288.3 Then I did this test with 10 workers. I only ran each test once and I didn't put any load on the workers, so didn't really flex the CoW situation: https://gist.github.com/jjb/d65bc10bb55fed7e4cafb07be035c10a the original implementation of compact ran a GC before and after https://bugs.ruby-lang.org/issues/15626 I don't know if that made it into the final implementation ruby/ruby@3c55b64 |
In a way yes - this is the premise of a Generational GC. In order for the test to be "fair" you'll have to put some load on your server after forking. The premise of nakayoshi_fork and compact-before-fork is that you improve copy-on-write by putting old objects all together on the fewest number of pages/space possible, which means you will do more copying and less writing as the server process takes requests. |
ah, gotcha
alas I don't have time right now to set something up. would be cool to do a test with https://github.com/noahgibbs/rsb/ |
Adding contrib-wanted if anyone wants to try to run those tests themselves. |
I'm thinking about putting this + compact behind an option for 5.0 and gathering data that way. |
sounds good to me! |
Closing in favor of #2256 |
Description
While doing some simple experiments with GC.compact in ruby 2.7 I noticed that
GC.start also had some benefits in the pre_fork phase. Since the master process won't be
growing (as much? at all?) as the forked processes, it might not ever get an organic GC, so this
is perhaps a good time to get in a manual one to save a meg or three.
(I actually don't know if the garbage collection done by GC.start reduces forked memory and/or CoW effeciency — if so, an even better idea to do it for all ruby versions).
Your checklist for this pull request
[changelog skip]
the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.