Go编译依赖项和源代码需要多少内存



我面临的问题是,我们有一个拥有500MB RAM和2CPU内核的docker容器,这使得编译变得很难。有时有效,有时无效。虽然显而易见的解决方案是增加RAM内存,但我们不能继续增加内存。

因此,我的问题是,给定一组依赖项,是否可以预先确定编译go代码所需的内存,如果可以,如何确定?

虽然有pprof,但它似乎是为了跟踪应用程序内存。

以下结果取自戈朗奇皮棉

执行的命令:

golangci-lint run --issues-exit-code 1 --no-config --disable-all -E typecheck --enable=gosec --enable=unparam --enable=unconvert --enable=gocritic  --enable=ineffassign --enable=staticcheck --enable=dupl --enable=gocyclo --enable=gofmt --enable=golint --enable=deadcode --enable=errcheck --enable=gosimple --enable=govet --enable=structcheck --enable=typecheck --enable=unused --enable=varcheck

结果:

INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 22 samples, avg is 58.7MB, max is 66.8MB 
INFO Execution took 2.063380705s 

[I]是否可以预先确定编译go代码所需的内存[?]

否。很抱歉

你不能"预先确定";容器的内存要求。即使你确切地知道构建过程使用了多少,容器也会使用不同的数量——想想文件缓冲区和缓存

计算编译最佳内存的一种方法是使用以下工具https://github.com/facebookincubator/senpai其分析负载下的集装箱。

当然,如果正在编译的东西发生了变化,那么它将需要不同数量的内存,但估计是可能的

最新更新