Build Semaphore: Working prototype. #971
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is meant as a working prototype for a feature I'd like to discuss -
play around with it and see if there's enough interest to develop a serious
implementation from that.
How it works
Create a semaphore, to restrict the number of builders that may enter the
build
phase of their ports. This number is controlled by theBUILD_SEMAPHORE
setting. With a setting of e.g.BUILD_SEMAPHORE=3
, no morethan 3 builders are allowed to enter the
build
phase at a time. Other phasesare unaffected, they are only limited by the total number of builders
(
PARALLEL_JOBS
).Rationale
Like others I struggle to find a good compromise between many builders
(
PARALLEL_JOBS
) and high build concurrency (MAKE_JOBS
) that:The problem of 1. and 3. is that it requires high build concurrency but few
builders, during the
build
phase. While 2. demands more builders, thatspend most of their time single threaded in the configure and dependency
phases.
Now with the build semaphore, there is a way to have a decent number of
builders working on 2., while allowing high build concurrency for 1. - since
concurrency only affects the
build
phase, system load is then restrictedby the semaphore (3.).
Assumptions
As a reality check, effectiveness of the semaphore approach is based on the
following assumptions:
build
phase of ports is either short or makes use of concurrency.To my knowledge, this holds true for the vast majority of ports.
Example
Old Xeon workstation with 12C/24T, 48GB RAM. For most of the ports, 6 builders
with
-j6
works fine, but for the heavy ones I'd want to use 2 builders with-j18
. An uncached build of chromium with-j18
takes about 5h, I never triedwith less (and I don't intend to).
Therefore my current settings are
PARALLEL_JOBS=6
,BUILD_SEMAPHORE=2
, andMAKE_JOBS_NUMBER=18
inmake.conf
. This gives me approximately the overallspeed of 6 builders for the lightweight ports, but with
-j18
for the heavyones. System load never exceeds 40, which is bearable on this machine.
It's not perfect, some ports tend to have long single threaded link times,
which hurts efficiency a bit with a build semaphore of 2. But all in all it's a
lot faster and more adaptive than anything else I tried.
Caveats
I'm obviously not an experienced shell programmer. The semaphore implementation
is hand-crafted, although apparently working. And the
lockf
should make itsafe and fair.