Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel consumes too much memory and hangs in docker container #3645

Closed
alexeagle opened this issue Aug 30, 2017 · 17 comments
Closed

Bazel consumes too much memory and hangs in docker container #3645

alexeagle opened this issue Aug 30, 2017 · 17 comments
Assignees
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug

Comments

@alexeagle
Copy link
Contributor

Description of the problem / feature request / question:

I have a sass_binary rule from https://github.com/bazelbuild/rules_sass
And build in this docker image on CircleCI
https://github.com/alexeagle/ngcontainer/blob/master/Dockerfile

Most of the time the build hangs while compiling C++, but sometimes it succeeds.

If possible, provide a minimal example to reproduce the problem:

https://circleci.com/gh/alexeagle/angular-bazel-example/1
is a (somewhat) minimal example.
Source: https://github.com/alexeagle/angular-bazel-example

Environment info

  • Operating System:
    Debian linux (jessie) (in docker)

  • Bazel version (output of bazel info release):
    Build label: 0.5.1
    Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
    Build time: Tue Jun 6 10:34:11 2017 (1496745251)
    Build timestamp: 1496745251
    Build timestamp as int: 1496745251

Have you found anything relevant by searching the web?

(e.g. StackOverflow answers,
GitHub issues,
email threads on the bazel-discuss Google group)

Anything else, information or logs or outputs that would be helpful?

(If they are large, please upload as attachment or provide link).

@alexeagle
Copy link
Contributor Author

Confirmed this also happens on release 0.5.4

@alexeagle
Copy link
Contributor Author

Another sample, got a different behavior, instead of hanging it fails with an error:

ERROR: /root/.cache/bazel/_bazel_root/049ed6f058a98cba95753eee774cab7a/external/sassc/BUILD.bazel:4:1: C++ compilation of rule '@sassc//:sassc' failed (Exit 1)

external/libsass/src/sass.cpp:41:1: fatal error: error writing to /tmp/ccLTBo6L.s: Cannot allocate memory
 }
 ^
compilation terminated.
The bug is not reproducible, so it is likely a hardware or OS problem.

@vladmos vladmos added category: rules > C++ P2 We'll consider working on this in future. (Assignee optional) type: bug labels Sep 1, 2017
@alexeagle
Copy link
Contributor Author

Hi, this prevents Angular bazel apps from using CircleCI, which is our recommendation.
It also means the canonical demo app
https://github.com/alexeagle/angular-bazel-example
has a flaky build status, which looks bad.

Can someone triage this? I might be able to fix it if I could tell what is wrong.
/cc @davidstanke

@alexeagle
Copy link
Contributor Author

Ping!

@alexeagle
Copy link
Contributor Author

alexeagle commented Sep 23, 2017

@gregmagolan tracked it down (thanks!)

Under the docker container, the amount of memory available to a process is limited
https://docs.docker.com/engine/admin/resource_constraints/

Bazel should determine the amount of available RAM (you hint at this in https://docs.bazel.build/versions/master/user-manual.html#flag--ram_utilization_factor )
but that doesn't account for the cgroup limitation.
https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt

(Edited by @laszlocsomor on 2018/06/14: fix broken URL)

alexeagle added a commit to angular/angular-bazel-example that referenced this issue Sep 23, 2017
@alexeagle alexeagle changed the title Bazel C++ compilation hangs in docker container Bazel consumes too much memory and hangs in docker container Sep 23, 2017
@djudd-stripe
Copy link

Underlying issues might be #3886 plus #2946?

@laszlocsomor
Copy link
Contributor

/cc: @jhfield @ulfjack @ericfelly

Summary: #3645 (comment)

Who should work on this?

@ulfjack
Copy link
Contributor

ulfjack commented Jun 14, 2018

We have no idea what's going on there, and I don't think we can debug this without seeing jvm.out. In order to get better debug information in the future, we will also need to add code to bazel client to cat jvm.out.

@ulfjack
Copy link
Contributor

ulfjack commented Jun 14, 2018

This isn't the first time that not having jvm.out is preventing us from making progress.

@ittaiz
Copy link
Member

ittaiz commented Jun 14, 2018 via email

whilp added a commit to whilp/dotfiles that referenced this issue Oct 7, 2018
Builds are timing out, eg:

https://travis-ci.org/whilp/dotfiles/builds/438142354

Perhaps this is because bazel's estimates for available resources
aren't super when running in docker.

bazelbuild/bazel#3645
bazelbuild/bazel#2946
@hlopko hlopko added team-Rules-CPP Issues for C++ rules and removed category: rules > C++ labels Oct 11, 2018
@Globegitter
Copy link

I have run into similar issues and the jvm.out has nothing relevant, just the some warnings that I believe are always there.

vmax added a commit to hasadna/monorepo that referenced this issue Apr 9, 2019
- Upgrade `bazel` to `0.24.0`
- Restructure `.circleci/config.yml` to use `machine` executor. This removes memory limitations (see bazelbuild/bazel#3645) and removes the need to upgrade `libstdc++` (Ubuntu's bundled on is up-to-date enough)
- Disable building code multiple times on CircleCI
@meteorcloudy
Copy link
Member

@ulfjack This issue is still bothering Angular. Is it possible to make Bazel auto-tune the memory usage (eg. adjusting the parallel job number) according to the RAM size?

@c-mita c-mita added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) labels Nov 24, 2020
@fmeum
Copy link
Collaborator

fmeum commented Feb 17, 2023

@sgowroji Not stale, has a Bazel team assignee.

@larsrc-google
Copy link
Contributor

I think #16512 does fix this.

@fmeum
Copy link
Collaborator

fmeum commented Apr 26, 2023

@larsrc-google Please reopen, my fix only applied to CPU shares, not RAM.

@larsrc-google
Copy link
Contributor

The memory usage in general is hard to control - Bazel needs to hold your build graph in memory. The amount of parallel actions can be controlled with --jobs, e.g. --jobs=HOST_RAM*0.01, together with --local_ram_resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
14 participants