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

Match concurrency to available CPU bandwidth #2300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maxim-kuvyrkov
Copy link

This change allows ninja to throttle number of parallel tasks based on feedback from Linux kernel's PSI (Pressure Stall Information) interfacts. It extends "-l" parameter to accept negative values; "-l-NN" means that ninja should limit concurrency when processes in current cgroup spend more than NN% of their time stalled on CPU.

E.g., running "ninja -j100 -l-10" on a 32-core machine will quickly settle on parallelism of 32-34.

This option is designed to make ninja use all CPU bandwidth available to a cgroup-based container, while not starting excessive number of processes, which could eat up all RAM.

The motivation for this feature is too automatically reduce parallelism when the system is about to run out of RAM. If the system has swap enabled, "ninja -l-10" will dance with parallelism on the edge of just using a bit of swap. As soon as a process starts swapping, that increases CPU "stalled" cycles, and parallelism is reduced. The same argument works when a process is waiting for its turn to use IO and/or network.

This change allows ninja to throttle number of parallel tasks based
on feedback from Linux kernel's PSI (Pressure Stall Information)
interfacts.  It extends "-l" parameter to accept negative values;
"-l-NN" means that ninja should limit concurrency when processes
in current cgroup spend more than NN% of their time stalled on CPU.

E.g., running "ninja -j100 -l-10" on a 32-core machine will quickly
settle on parallelism of 32-34.

This option is designed to make ninja use all CPU bandwidth available
to a cgroup-based container, while not starting excessive number of
processes, which could eat up all RAM.

The motivation for this feature is to automatically reduce
parallelism when the system is about to run out of RAM.
If the system has swap enabled, "ninja -l-10" will dance with
parallelism on the edge of just using a bit of swap.  As soon as
a process starts swapping, CPU "stalled" cycles increase, and
parallelism is reduced.  The same argument works when a process is
waiting for its turn to use IO and/or network.
Copy link
Contributor

@Flowdalic Flowdalic left a comment

Choose a reason for hiding this comment

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

Nice idea using PSI information. This is probably what you want: build systems to dynamically control their parallelism. This is similar to what I did in #1949, albeit slightly less portable.

src/util.cc Show resolved Hide resolved
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.

2 participants