3 ms·
Using the SetGCPercent option with a large value is dangerous, it may cause a program never get GCed before virtual memory is exploited. And when this happens,
by tapirl 9y ago
Using the SetGCPercent option with a large value is dangerous, it may cause a program never get GCed before virtual memory is exploited.
And when this happens, Go programs will become very very slow.
The current official Go runtime performs very very poorly when virtual memory is involved. It may make the while OS non-interactive so that you must restart your computer.
A SetGCMemoryThreshold(maxMemory int) opition is better for many programs.
- twotwotwo 9y agoDefinitely agree option of a memory limit would be handy in a lot of cases. Sometimes a box exists to run one service and you know you want like 75% of the box's RAM (leaving some for cache, other procs, etc.). Other times, like this, you don't want GOGC=100's frequent collections but also don't want the risk of an explosion if live data increases. Just adding some heuristics to override GOGC's behavior in extreme cases could help, e.g. assume by default OK to use 1% of system RAM and not OK to use >75% of it regardless of live data. I'm not sure we can realistically hope to get that--adds complexity, folks dislike arbitrary thresholds, and any change will break users who have optimized around current behavior. It might be you could approximate the desired behavior for reasonably well-behaved programs from a third-party package using runtime methods and a timer, but that's a drag.