Thursday, 28 January 2010

Emerge multiple packages at once

You may or may not already know about this feature, but you can emerge multiple packages at once in Gentoo.  If you have any semi-recent machine (2 years old or newer) you should definitely be using it.

Being source based - and hence compiling everything before you install it - any build time speed improvements are welcome.  We already have the -j option which can be passed to make via make.conf:
Various sources say to set this number j = N(CPU) + 1 or j = 2N(CPU) + 1.  I find the former is sufficient.

But what about configure?  Before you compile a package, you have to configure it, which typically can only use one CPU.  In addition there are other operations that are disk-intensive while not being CPU intensive (for instance, unpacking source code).  And finally some packages are just "broken" and internally set -j1.

So it would be nice to build (unrelated) packages simultaneously.  While one configure script is running, another could be compiling, further utilising those MeGaHurTz you paid so dearly for!  Recently I tested this for the first time.  I ran emerge like so:
$ emerge -vauDN --jobs=2 world

After looking through the output, this is how it proceeds:
Total: 70 packages (66 upgrades, 1 new, 3 reinstalls, 3 uninstalls), Size of downloads: 0 kB
Conflict: 23 blocks
Portage tree and overlays:
 [0] /usr/portage
 [1] /usr/local/portage

>>> Verifying ebuild manifests
>>> Starting parallel fetch
>>> Emerging (1 of 70) x11-libs/qt-xmlpatterns-4.6.1
>>> Emerging (2 of 70) sys-devel/binutils-2.20
>>> Jobs: 0 of 70 complete, 2 running               Load avg: 5.56, 2.53, 1.67

And just to prove that two packages are emerging:
$ genlop -c

 Currently merging 2 out of 70

 * sys-devel/binutils-2.20 

       current merge time: 1 minute and 27 seconds.
       ETA: less than a minute.

 Currently merging 1 out of 70

 * x11-libs/qt-xmlpatterns-4.6.1 

       current merge time: 1 minute and 28 seconds.
       ETA: less than a minute.

A little while later, my load average settles down around 4.8:
>>> Installing (18 of 70) dev-python/pytz-2010b
>>> Installing (16 of 70) x11-libs/qt-script-4.6.1
>>> Emerging (19 of 70) dev-util/subversion-1.6.9
>>> Emerging (20 of 70) dev-lang/python-2.6.4-r1
>>> Jobs: 17 of 70 complete, 1 running              Load avg: 4.84, 4.84, 3.94

You may come across some packages that are interactive, such as skype, which forces you to view and accept their EULA.  In that case the concurrent jobs are disabled.  If you wish to go ahead with all non-interactive jobs (a good idea!) run emerge like so:

$ emerge -vauDN --jobs=2 --accept-properties=-interactive world

Note this feature is not supported in older versions of portage.  I tested with sys-apps/portage-


Anonymous said...

Very useful option. I wasnt aware of that


Jeremy Olexa said...

Hey, glad you found this option. I just want to point out what I wrote for some months ago :)

pepoluan said...

So, leaving out the interactive jobs will not emerge them, and I can later do another 'emerge -vauDN world' to just handle those interactive jobs. Am I getting it right?

Copyright 2009 Another Blog. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan