-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
runtime: GOGC and GOMEMLIMIT performance comparison #68346
Comments
Hi @MikeMitchellWebDev, after a brief look, I'm not sure this is a bug. One question for you: are you setting If so, no matter how hard the GC works, it cannot drive down the process memory usage below the live heap memory, so I think it is expected that the GC will work very hard in that case (where "very hard" might mean running continuously and/or using up to ~50% of the total CPU available). Also, note that when the memory managed by the runtime gets close to the |
Said another way — I think the opening comment of "the application by chance maintained a 1GiB heap goal" is not quite accurate... and if you give the GC a small amount of headroom with |
I think it's about the same as the gctraces show in the OP. |
What @thepudds says is exactly right, and from the gctraces you posted, it looks like you're oversaturating the limit. AFAICT, you're basically asking the GC to do something impossible, and it's doing its best (with some guardrails to prevent total performance collapse). I don't think it makes sense to consider a performance comparison between One could imagine another tuning knob to control how hard the GC works to maintain the memory limit under such conditions. But there are high costs to adding more "knobs" to the GC (see the original In any case, I don't think there's anything actionable here. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran the same app with
GOGC=3
and then ran it again withGOMEMLIMIT=1GiB and GOGC=10000
You can reproduce the issue with my gc_knobs application and the linux repo by doing this in one terminal window
GODEBUG=gctrace=1 GOGC=3 ./gc_knobs
and in another terminal window run
curl -H 'Content-Type: application/json' -d '{"path":"/your/path/to/linux", "repeat":"1", "sleep":"2"}' -X POST http://localhost:8000/git_repo
https://github.com/MikeMitchellWebDev/gc_knobs
https://github.com/torvalds/linux
What did you expect to see?
What did you see instead?
With GOMEMLIMIT=1GiB and GOGC off (i.e. GOGC=100000) , there were almost 4000 gcs while the appliction took about 6 minutes to run
With GOGC=3 , there were 5 times fewer gcs (800 vs 4000) and the application took 3 minutes to run
The only reason I am filing a possible bug report is that, with GOGC set to 3, the application by chance maintained a 1GiB heap goal. Therefore, this raises the possibility of comparing performance of GOGC and GOMEMLIMIT, as GOMEMLIMIT also maintained a 1GiB memory limit, but did so at a much higher performance cost (in terms of the number of GCs and the application running time).
Therefore, I'm wondering if this raises the possibility that GOMEMLIMIT could accomplish the same goal without such a heavy performance cost.
These lines from GODEBUG=gctrace=1 is fairly typical for the whole application running time when GOMEMLIMIT is set to 1GiB. Namely, the liveHeap at the end of the last GC is the same as the nextGC goal, so the gc is constantly running.
For comparison's sake, this is the GODEBUG=gctrace=1 output while running the application with GOGC=3 and GOMEMLIMIT off
The text was updated successfully, but these errors were encountered: