golang fork/exec cannot allocate memory错误问题
修改 /proc/sys/vm/overcommit_memory 参数为1
echo 1 > /proc/sys/vm/overcommit_memory
/usr/local/go/pkg/tool/linux_amd64/6l: running gcc failed: Cannot allocate memory
在google上查找解决方案未果,这个问题与 gcc 分配内存有关,gcc版本 :
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
我在一台机器启动了4个容器后,想启动第五个容器的时候报了相同的错误,然后停掉之前的一个容器后再启动就不会报错了。我的机器本来内存就不大,应该就是内存问题。
runtime: failed to create new OS thread (have 3 already; errno=12)
运行时:无法创建新的OS线程
os.Exec()
to spawn hundreds of client processes, and manage them with an abundance of goroutines.
Sometimes, but not always, I get this:
runtime: failed to create new OS thread (have 1306 already; errno=11)
runtime: may need to increase max user processes (ulimit -u)
fatal error: newosproc
My ulimit is pretty high already:
$ ulimit -u
1828079
There’s never a problem if I limit myself to, say, 54 clients.
Is there a way I can handle this situation more gracefully? E.g. not bomb out with a fatal error, and just do less/delayed work instead? Or query the system ahead of time and anticipate the maximum amount of stuff I can do (I don’t just want to limit to the number of cores though)?
Given my large ulimit, should this error even be happening?
grep -c goroutine
on the stack output following the fatal error only gives 6087. Each client process (of which there are certainly less than 2000) might have a few goroutines of their own, but nothing crazy.
Edit: the problem only occurs on high-core machines (~60). Keeping everything else constant and just changing the number of cores down to 30 (this being an OpenStack environment, so the same underlying hardware still being used), these runtime errors don’t occur.
https://dev.to/j4ng5y/how-i-do-go-application-configuration-in-2020-336b