The problem I'm facing is that we have a docker container with 500MB RAM and 2CPU cores makes the compilation flaky. Sometimes it works and other times it doesn't. While the obvious solution is to increase the RAM memory we can't keep on increasing the memory.
Hence my question is, given a set of dependencies is it possible to pre-determine the memory needed to compile my go code and if so how?
While there is pprof, it seems it is to track the application memory.
The following results are taken from golangci-lint
Command executed:
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
Results:
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
CodePudding user response:
[I]s it possible to pre-determine the memory needed to compile my go code [?]
No. Sorry.
CodePudding user response:
You can't "predetermine" the memory requirements for the container. Even if you knew exactly how much the go build process used, the container would use a different amount - think of file buffers and cache
One way to work out the optimum memory for compiling is to use a tool like https://github.com/facebookincubator/senpai which analyses the container under load.
Of course if the thing being compiled changes then it will need a different amount of memory but estimation is possible
