GoLang Uses All Available Memory in Docker

Docker Executor and Go

When building Go projects on CircleCI using the Docker executor, memory issues can occur because:

  • Go will try to optimize according to the number of cores reported on the system.
  • The environment will report the number of cores on the VM rather than the available cores for the container.

This can cause Go to spawn too many workers and use all the available memory.

You can control the maximum number of OS threads that are executing code simultaneously, by setting the GOMAXPROCS variable to the number of cores available to your job.

For example, if you're using the default resource class (medium) for Docker executor jobs (which has 2 cores available):

jobs:
  build:
    docker:
    - image: circleci/golang:1.12
    environment:
      GOMAXPROCS: 2
    steps:
      - run:

 

To learn more about how to control the run-time behavior of Go programs, see the GoLang documentation.

 

Additional Resources:

Was this article helpful?
4 out of 5 found this helpful

Comments

0 comments

Article is closed for comments.