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

[Feature] Configuring the number of parallel jobs #152

Open
memchr opened this issue Aug 20, 2023 · 6 comments
Open

[Feature] Configuring the number of parallel jobs #152

memchr opened this issue Aug 20, 2023 · 6 comments

Comments

@memchr
Copy link

memchr commented Aug 20, 2023

Issue

Ninja, the build system used by Meson, currently uses all available hardware threads + 2 (i.e. logical CPU count + 2) to run compilation jobs in parallel.

This is unsafe on hardware with a high logical CPU count and relatively low available memory. (e.g. on a system with 32 hardware threads but only 32 GiB of memory). As it can cause the following problem

  • Reduce system responsiveness
  • A large number of parallel compilation jobs will quickly consume all available memory, leading to havey swapping, OOM kill and, in the worst case, a system freeze or crash.
  • High usage of all CPU cores can lead to high core temperatures, especially on laptops where the cooling system may not be able to effectively lower the excessive temperature, resulting in potential hardware damage if the compilation takes a long time.

As stated in ninja-build/ninja#1441, there is no mechanism in Ninja where an environment variable can be used to control the number of parallel jobs. So tasks.options.env cannot be used to work around this problem.

Based on my limited and possibly inaccurate observations, the Ninja project won't be adding support for configuring the number of parallel jobs or passing flags via environment variables in the foreseeable future.

My apologies if there are any inaccuracies in the above statements.

Conclusion

In light of the above, it may be considered reasonable and to introduce an option in this extension to conveniently limit the number of parallel jobs in Ninja.

Possible workarounds

  • start vscode with taskset
taskset -c 0-3 code
  • create a shell script wrapper for ninja that passes the -j flag
  • use an alternative implementation of ninja
  • locally patch the ninja source to support ninja flags in environment variables.

Notes

  • tasks.runOptions.instanceLimit is unrelated to limiting parallel Ninja jobs

Thank you very much for generously volunteering your time and skills to contribute to this important project.

@xclaesse
Copy link
Member

Makes sense indeed, could you make a PR to add that option please?

@memchr
Copy link
Author

memchr commented Aug 20, 2023

Sorry, I currently do not possess the necessary skills to write typescript, otherwise I would certainly submit a PR request instead of an issue.

@tristan957
Copy link
Contributor

I am a little bit confused why you can't pass the -j flag to Meson in our various option settings. I might also be a little confused, so bear with me :)

@memchr
Copy link
Author

memchr commented Aug 21, 2023

I haven't found any options in package.json that allow me to pass meson flags, nor any environment variables in meson's documentation. So I am currently creating a wrapper script for ninja as a workaround, but if you know of any such options, please enlighten me.

@xclaesse
Copy link
Member

@tristan957 We have settings to set meson setup options, but not for meson compile AFAIK.

@tristan957
Copy link
Contributor

Sounds like a pretty easy feature to add, since it is basically copy-paste.

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

No branches or pull requests

3 participants