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

runtime: GC can thrash on very small heaps #22743

aclements opened this issue Nov 15, 2017 · 1 comment

runtime: GC can thrash on very small heaps #22743

aclements opened this issue Nov 15, 2017 · 1 comment


Copy link

@aclements aclements commented Nov 15, 2017

In applications with very small heaps and high allocation rates, the garbage collector can consume a large amount of CPU by running very frequently. This particularly affects microbenchmarks, which often have virtually no live heap, causing a full GC cycle every 4MB of allocation. We've seen this several times, and Cloudflare just blogged about this problem:

We should consider rate-limiting the garbage collector, allowing the heap to grow beyond the goal if the GC is running too frequently or using too much CPU. We could potentially replace the (rather arbitrary) 4MB lower-bound on heap size with a more principled rate-limiting system.

One possible approach is to enforce an upper bound on GC utilization. This could be measured GC CPU overhead (e.g., MemStats.GCCPUFraction) or simply the ratio of GC active wall-clock time to total wall-clock time. The GC trigger would be delayed until this metric drops below the upper bound. This should prevent thrashing.

With this approach, we could also enforce a lower bound, which could be a more principled replacement for the current 2 minute forced GC. This should prevent starvation.

@RLH and I have talked about this several times, but apparently neither of us filed an issue to track it. I'm correcting that. :)

@aclements aclements added this to the Go1.11 milestone Nov 15, 2017
@aclements aclements changed the title runtime: consider rate-limiting GC runtime: GC can thrash on very small heaps Nov 15, 2017
@bradfitz bradfitz removed this from the Go1.11 milestone Jun 20, 2018
@bradfitz bradfitz added this to the Go1.12 milestone Jun 20, 2018
Copy link
Member Author

@aclements aclements commented Dec 18, 2018

The actual problem here is that we fail to amortize the cost of GC on small heaps. I've detailed the problem in #23044 (comment).

@aclements aclements removed this from the Go1.12 milestone Dec 18, 2018
@aclements aclements added this to the Go1.13 milestone Dec 18, 2018
@aclements aclements removed this from the Go1.13 milestone Jun 25, 2019
@aclements aclements added this to the Go1.14 milestone Jun 25, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants