]> git.ipfire.org Git - pakfire.git/commitdiff
Automatically calculate parallelism flags.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Feb 2011 21:29:50 +0000 (22:29 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Feb 2011 21:29:50 +0000 (22:29 +0100)
pakfire/builder.py

index 23efb12679f860e7b986f9dd0edae29acf704c80..927ddfa5c9a3b68a3c862a3ac97fe3b7f3bf09b8 100644 (file)
@@ -3,6 +3,7 @@
 import fcntl
 import grp
 import logging
+import math
 import os
 import re
 import shutil
@@ -304,10 +305,25 @@ class Builder(object):
 
                return ret
 
+       @staticmethod
+       def calc_parallelism():
+               """
+                       Calculate how many processes to run
+                       at the same time.
+
+                       We take the log10(number of processors) * factor
+               """
+               num = os.sysconf("SC_NPROCESSORS_CONF")
+               if num == 1:
+                       return 2
+               else:
+                       return int(round(math.log10(num) * 26))
+
        @property
        def environ(self):
                env = {
                        "BUILDROOT" : self.buildroot,
+                       "PARALLELISMFLAGS" : "-j%s" % self.calc_parallelism(),
                }
 
                # Inherit environment from distro