[lorax][PATCH] Run compressions in multiple threads

Vratislav Podzimek vpodzime at redhat.com
Wed Nov 13 08:39:34 UTC 2013


This speeds up compression a lot on multicore systems.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 lorax.spec              | 1 +
 src/pylorax/imgutils.py | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/lorax.spec b/lorax.spec
index db0cede..3b8302a 100644
--- a/lorax.spec
+++ b/lorax.spec
@@ -32,6 +32,7 @@ Requires:       python-mako
 Requires:       squashfs-tools >= 4.2
 Requires:       util-linux
 Requires:       xz
+Requires:       pigz
 Requires:       yum
 Requires:       pykickstart
 Requires:       dracut >= 030
diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py
index 94dda5a..608607a 100644
--- a/src/pylorax/imgutils.py
+++ b/src/pylorax/imgutils.py
@@ -25,6 +25,7 @@ from os.path import join, dirname
 from subprocess import CalledProcessError
 import sys
 import traceback
+import multiprocessing
 from time import sleep
 
 from pylorax.sysutils import cpfile
@@ -44,6 +45,13 @@ def mkcpio(rootdir, outfile, compression="xz", compressargs=["-9"]):
     if compression is None:
         compression = "cat" # this is a little silly
         compressargs = []
+
+    # make compression run with multiple threads if possible
+    if compression in ("xz", "lzma"):
+        compressargs.insert(0, "-T%d" % multiprocessing.cpu_count())
+    if compression == "gzip":
+        compression = "pigz"
+
     logger.debug("mkcpio %s | %s %s > %s", rootdir, compression,
                                         " ".join(compressargs), outfile)
     find = Popen(["find", ".", "-print0"], stdout=PIPE, cwd=rootdir)
-- 
1.8.4.2



More information about the anaconda-patches mailing list