Instead of using nice
, consider using the other options the CPU management docker API gives you:
docker build --help | grep cpu
--cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota
-c, --cpu-shares int CPU shares (relative weight)
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
For example, I've recently updated some of my builds to reserve 1 of 6 of the CPU cores I have on one of our build machines with a command like this:
docker build --cpuset-cpus 0-4 .
It doesn't appear that any of these options are backed by a nice value so you might want to experiment to see what works best for you. I posted some quick tests I ran but these could be improved by running a longer test and having something using CPU on the host to better simulate sharing.
--cpu-period="100000" --cpu-quota="150000"
docker run --name 7z --rm -it --cpu-period="100000" --cpu-quota="150000" localhost/7z bash -c 'time dd if=/dev/zero bs=50K count=1K | 7zr -si a out.7z'
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,12 CPUs Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz (306F2),ASM,AES-NI)
Creating archive: out.7z
Items to compress: 1
0M1024+0 records in
1024+0 records out
52428800 bytes (52 MB, 50 MiB) copied, 0.0942925 s, 556 MB/s
Files read from disk: 1
Archive size: 7815 bytes (8 KiB)
Everything is Ok
real 0m2.326s
user 0m3.078s
sys 0m0.359s
--cpu-shares 500
docker run --name 7z --rm -it --cpu-shares 500 localhost/7z bash -c 'time dd if=/dev/zero bs=50K count=1K | 7zr -si a out.7z'
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,12 CPUs Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz (306F2),ASM,AES-NI)
Creating archive: out.7z
Items to compress: 1
0M1024+0 records in
1024+0 records out
52428800 bytes (52 MB, 50 MiB) copied, 0.08448 s, 621 MB/s
Files read from disk: 1
Archive size: 7815 bytes (8 KiB)
Everything is Ok
real 0m1.982s
user 0m2.961s
sys 0m0.343s
nice
docker run --name 7z --rm -it localhost/7z bash -c 'time dd if=/dev/zero bs=50K
count=1K | nice 7zr -si a out.7z'
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,12 CPUs Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz (306F2),ASM,AES-NI)
Creating archive: out.7z
Items to compress: 1
0M1024+0 records in
1024+0 records out
52428800 bytes (52 MB, 50 MiB) copied, 0.0928115 s, 565 MB/s
Files read from disk: 1
Archive size: 7815 bytes (8 KiB)
Everything is Ok
real 0m2.026s
user 0m3.066s
sys 0m0.375s
--cpuset-cpus 0-1
docker run --name 7z --rm -it --cpuset-cpus 0-1 localhost/7z bash -c 'time dd if=/dev/zero bs=50K count=1K | 7zr -si a out.7z'
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,12 CPUs Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz (306F2),ASM,AES-NI)
Creating archive: out.7z
Items to compress: 1
0M1024+0 records in
1024+0 records out
52428800 bytes (52 MB, 50 MiB) copied, 0.0868617 s, 604 MB/s
Files read from disk: 1
Archive size: 7815 bytes (8 KiB)
Everything is Ok
real 0m1.908s
user 0m2.432s
sys 0m0.295s
nothing (control)
docker run --name 7z --rm -it localhost/7z bash -c 'time dd if=/dev/zero bs=50K count=1K | 7zr -si a out.7z' 1 ↵
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,12 CPUs Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz (306F2),ASM,AES-NI)
Creating archive: out.7z
Items to compress: 1
0M1024+0 records in
1024+0 records out
52428800 bytes (52 MB, 50 MiB) copied, 0.0938064 s, 559 MB/s
Files read from disk: 1
Archive size: 7815 bytes (8 KiB)
Everything is Ok
real 0m2.036s
user 0m3.021s
sys. 0m0.389s