Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 490620 - multiprocessing.eclass should include support for --load-average along with --jobs
Summary: multiprocessing.eclass should include support for --load-average along with -...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: 490624
  Show dependency tree
 
Reported: 2013-11-06 22:04 UTC by M. B.
Modified: 2013-11-28 20:49 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
multiprocessing.eclass (multiprocessing.eclass,7.88 KB, text/plain)
2013-11-06 22:06 UTC, M. B.
Details
multiprocessing.eclass.patch (file_490620.txt,1.16 KB, patch)
2013-11-09 23:37 UTC, Tom Wijsman (TomWij) (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description M. B. 2013-11-06 22:04:13 UTC
When building large packages make.conf provides one with the option to modify the options passed on to `make` and thereby limit the resources allotted to building processes.
One option in particular is -j (--jobs), which limits the number of simultaneous jobs to a pre-defined value.
The multiprocessing.eclass provides ebuild-writers with the option to directly get this value via $(makeopts_jobs).

For large builds, however, the number of simultaneous processes is often not the limiting factor - IO is. Therefor make provides the option -l (or --load-average) as another constraint: no new build-processes are started as long as the current load is higher than the (floating-point) value provided.

This would be especially valuable for big packages like boost or chromium (both of which already use makeopts_jobs().

Please note that emerge provides similarly named options; these only apply to parallel merges, not to the build-processes, handled by make or other build-systems (like ninja in chromium's case).

Reproducible: Always
Comment 1 M. B. 2013-11-06 22:06:58 UTC
Created attachment 362706 [details]
multiprocessing.eclass

added the function makeopts_loadavg(), based on makeopts_jobs().


$ diff -Naur /usr/portage/eclass/multiprocessing.eclass multiprocessing.eclass 
--- /usr/portage/eclass/multiprocessing.eclass	2013-10-12 23:31:16.000000000 +0200
+++ multiprocessing.eclass	2013-11-06 22:30:03.487129897 +0100
@@ -55,6 +55,25 @@
 	echo ${jobs:-1}
 }
 
+# @FUNCTION: makeopts_loadavg
+# @USAGE: [${MAKEOPTS}]
+# @DESCRIPTION:
+# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the value set
+# for load-average. For make and ninja based builds this will mean new jobs are 
+# not only limited by the jobs-value, but also by the current load - which might 
+# get excessive due to I/O and not just due to CPU load.
+# Be aware that the returned number might be a floating-point number. Test
+# whether your software supports that.
+makeopts_loadavg() {
+	[[ $# -eq 0 ]] && set -- ${MAKEOPTS}
+	# This assumes the first .* will be more greedy than the second .*
+	# since POSIX doesn't specify a non-greedy match (i.e. ".*?").
+	local lavg=$(echo " $* " | sed -r -n \
+		-e 's:.*[[:space:]](-l|--load-average[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+)[^0-9.]*:\2:p' \
+		-e 's:.*[[:space:]](-l|--load-average)[[:space:]].*:999:p')
+	echo ${lavg:-1}
+}
+
 # @FUNCTION: multijob_init
 # @USAGE: [${MAKEOPTS}]
 # @DESCRIPTION:
Comment 2 Tom Wijsman (TomWij) (RETIRED) gentoo-dev 2013-11-09 23:37:03 UTC
Created attachment 362932 [details, diff]
multiprocessing.eclass.patch

Attached patch from comment such that it can be downloaded.
Comment 3 Rick Farina (Zero_Chaos) gentoo-dev 2013-11-14 16:15:41 UTC
it should be noted, that --load-average on MAKEOPTS finds some impressive bugs.

MAKEOPTS="-j300 -l5" should mean "you can start up to 300 jobs as long as load is below 5" but what it actually seems to mean is "break up the work into 300 segments and then run a segment when you have load below 5".  That means that it will often stall in a work chain much longer than expected and it finds parallalization issues when things are not properly deped in the Makefile. I'm not saying to do this or not to, I'm just saying it finds a lot of bugs that I know I can't fix.
Comment 4 SpanKY gentoo-dev 2013-11-28 07:17:00 UTC
Comment on attachment 362706 [details]
multiprocessing.eclass

we like to see patches, not whole files
Comment 5 SpanKY gentoo-dev 2013-11-28 07:19:12 UTC
Comment on attachment 362932 [details, diff]
multiprocessing.eclass.patch

seems like a straightforward implementation