0

For reference: How can I make garbage collection steal less of my resources during spikes in allocations?

My question is very specific: how can I prevent Go's garbage collection from breaking down in applications that allocate a lot of memory in short bursts?

I'm having trouble understanding what about this is unfocused.

11
  • 7
    I'm not saying I agree with the close reason, but perhaps a minimal reproducible example illustrating the behavior would inoculate your question from that particular close reason. Commented Jun 22, 2024 at 22:49
  • 7
    @MisterMiyagi I'm honestly not sure this question is either too broad or lacking focus, though. It seems pretty specific to me. Commented Jun 23, 2024 at 6:00
  • 2
    @RyanM Being specific does not meant that the answer can be specific enough. It is possible that question is also either unclear or lacks MRE. Two Go gold badge holders participated in closing so I guess they know why they closed it. The content in link posted in comments looks broad enough to say that question might require a book to be answered. Now, I cannot say whether some more concise answer could be extracted from that based on the content in the question because I am not Go SME. Commented Jun 23, 2024 at 6:52
  • 3
    This question is fine and doesn't lack focus. Commented Jun 23, 2024 at 9:58
  • 1
    @chivracq what is then the difference between such canonical answer and reading the documentation posted in a link there? Don't get me wrong I don't have anything against such canonicals, but this would also require that someone actually knows and wants to write such an elaborate answer. Since two Go gold badge holders closed it, I am assuming that question is not specific enough to write an answer or that answer will not be any better than existing documentation. Commented Jun 23, 2024 at 20:02
  • 1
    @CollinDauphinee Would you be willing to post a self-answered question with the solution you've found? (You can attribute your colleague in the answer). There's clearly disagreement on whether the question is sufficiently focused, but I don't see any resolution happening here, other than the question being deleted. Perhaps with an answer, it might be easier for others to edit the new question to be sufficiently focused. Commented Jun 24, 2024 at 11:39
  • I wouldn't normally suggest posting a question that could potentially get several downvotes (given the response on this meta question, chances are high the meta effect will reach the new question), but you likely have more than enough rep to avoid running into any automated bans. The upside of adding an actually useful question is (hopefully) worth the effort, IMO. Commented Jun 24, 2024 at 11:40
  • @cigien Where is the solution and the colleague mentioned? Commented Jun 24, 2024 at 12:38
  • 1
    @eik There was a comment from the OP saying they'd found a solution with the help of a colleague. The comment is deleted now (or maybe it was deleted a while ago, and I hadn't refreshed the page before leaving the comment). I'll leave it up anyway for a bit so OP can see it. Commented Jun 24, 2024 at 12:52
  • 1
    @cigien Okay, thanks. I would assume the proposed solution would also help clear up whether the question as formulated would enable readers to help, or it was based on some information the colleague had, but was missing from the question, hinting more towards “needs detail”. Commented Jun 24, 2024 at 12:59
  • 2
    Yeah the wrong close reason being picked is a bit of an epidemic. Difficult questions (because Go is all fun and games until you have to face the fact that it does have a garbage collector) without any code, any debugging attempts and any configuration just don't stand a chance of being curated correctly, unfocused is the default "don't want to think much about it, I just want this closed" choice. Commented Jun 25, 2024 at 8:39

1 Answer 1

5

To chime in:

When this refresh occurs, I'm experiencing that the GC almost completely stops my service from doing any meaningful work for the duration of the GC, around 600-700 ms.

This may be true, but how do you know? I assume you have profiled your application, but where is this data?

The GC isn't stopping the world, but it's stealing so much of my processing time via gcAssistAlloc that there's little difference. My understanding is that it's doing this because the sharp increase in memory pressure causes it to think memory is being allocated faster than it can collect, so it aggressively steals CPU.

This is from https://go.dev/doc/gc-guide#Identiying_costs: “A large amount of cumulative time spent here (>5%) indicates that the application is likely out-pacing the GC with respect to how fast it's allocating.”

Did you mean that with “My understanding is ...” or where did you get that from?

I'm unable to change the implementation of this refresh, e.g. to implement pooling or throttle it; the data is fetched by a third party package.

Is there any way to make the GC stop stealing my CPU, or hint to it that it doesn't need to be so aggressive? In reality, there's virtually no memory pressure outside of the refresh.

Now we can only guess. Give it more RAM? How much RAM does it have, because “no memory pressure outside of the refresh” is obviously not very relevant.

Perhaps “change the implementation” you're “unable to change”, because it being Go and affecting the Go garbage collector, there is a good chance you have the source...

I would agree that “needs detail or clarity” would be better than “needs to be more focused”, but generally it would be helpful to

  1. have more data
  2. know what you tried already

and probably

  1. have a question there exists an answer to

If you present a system that allocates too much memory at one point, and you can't change that, and also you won't give it more memory because it's mostly not needed, and that has to be fast - you're in a tight spot there, with any language.

Again, I can't really vote for “unfocused”. But I'm also at loss at what kind of answer you expect, because you seem to imply that the obvious answers won't help, but some Go wizard might have some magical pixie dust or something...


Posting this as an “answer” because it's really unwieldy in comment format. I don't feel more competent to answer that than most of the people who commented, with them having obviously far more experience than I have.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.