Limiting the max heap size of a Go process

103 views
Skip to first unread message

Viktor Kojouharov

unread,
Nov 25, 2020, 7:44:07 AM11/25/20
to golang-nuts

Hi,

Is there a way to set a hard limit on the max heap size a process is allowed to consume, from within it?
It's almost never a problem for a process to consume as much memory as is available, however, I've ran into real-life cases in a k8s environment, where a pod with a Go process will get evicted, when the pod approaches the memory limit of the node it's on.

Reducing GOGC improves the situation, however it doesn't act as a limit. And depending on the amount of data that's going through the process, it will still get evicted when it saturates the memory. I could also slow the whole process down, giving the GC even more time to reclaim the memory, but that sounds like a big workaround.

Ian Davis

unread,
Nov 25, 2020, 11:26:49 AM11/25/20
to golan...@googlegroups.com
You may be interested in this issue, which also links to several relevant ones https://github.com/golang/go/issues/42805

The short answer is that there is currently no way to set a hard limit but there are discussions in progress on the best approach to handle the situation you describe.





Reply all
Reply to author
Forward
0 new messages