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

Add -XX:-MaxFDLimit to builder binaries to allow it use system open files limit #811

Closed
wants to merge 1 commit into from

Conversation

arunkumar9t2
Copy link
Contributor

@arunkumar9t2 arunkumar9t2 commented Aug 6, 2022

When compiling large modules we noticed KotlinKapt would fail with Too many open files on MacOS.

We increased the shell limit manually from default 256 to 65536. Verified by running ulimit -a

-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8176
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       5333
-n: file descriptors                65536

Even then the worker action failed, it seems that JVM has its own FD limit which can be changed to use the system/shell limits via -XX:-MaxFDLimit arg. Adding these to java_binary targets worked for us.

References:

@Bencodes
Copy link
Collaborator

Bencodes commented Aug 7, 2022

@oliviernotteghem is this the same fix that you mentioned using last week?

@restingbull
Copy link
Collaborator

Does this work with Java 8? The flags changed, which has been problematic.

@arunkumar9t2
Copy link
Contributor Author

Based on a cursory look, it does according to here https://gist.github.com/ndimiduk/a6c2aa781c20fb8bb9c20abbcf5bac4f

@oliviernotteghem
Copy link
Contributor

@Bencodes : this is actually the approach @nkoroste discussed. We worked around the issue at Uber by pruning transitives deps (which causes the # of file opened to decrease, since # of jar of the classpath is much smaller). Our initial fix was to limit the # of parallel jobs (it takes usually more than 1 compilation action to reach the 10k+ file opened at a given time), which obviously wasn't ideal IRT build time / parallelism.

@arunkumar9t2
Copy link
Contributor Author

We are also pruning transitive deps in library targets and did not face issue there. This happens in the binary target so transitives are not avoidable. More specifically we get this error when Dagger tries to generate classes in the Kapt action.

Bazel team prefers to adjust individual worker definitions instead of a global fix.

@@ -43,6 +43,10 @@ java_binary(
"@com_github_jetbrains_kotlin//:lib/jvm-abi-gen.jar",
"@com_github_jetbrains_kotlin//:lib/kotlin-compiler.jar",
],
jvm_flags = [
"-XX:-MaxFDLimit",
"-XX:+IgnoreUnrecognizedVMOptions",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially thought the flag was not supported in Java 8 so added this but it seems Java 8 is supported so this is not needed. #848 alone is fine I think.

@nkoroste
Copy link
Collaborator

nkoroste commented Aug 12, 2022

For more context, there is a similar change in bazel core here:
bazelbuild/bazel@30dd871

For us we needed this following change:
bazelbuild/bazel#15978

Which allowed us to add the following .bazelrc to solve Too many open files on MacOS

build:macos --host_jvmopt="-XX:-MaxFDLimit"
build:macos --jvmopt="-XX:-MaxFDLimit"

I think the cleanest fix would be to add this default on the low level toolchain and only apply it for macs/darwin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants