to observe the actual working of "nice" utility in linux, I wrote a python script to calculate SHA512 non-stop.
- Preparation -
a Dual Core Linux Machine, a Single Core Linux Machine ( actually, they are both cloud instances )
a python script to calculate SHA512 non-stop, consumes 100% CPU time when running alone.
- Experiment -
on Single Core Machine
start this script normally, then
nice -n 15 python load_generator.py, give the second python process a low priority.
on Dual Core Machine
because only start two processes can not prove the point, I normally start 2 processes, then
nice -n 15 python load_generator.pya new process.
- Expected Outcome -
the normally started python process takes far more CPU time/Usage Percentage than
nice started process on both machines.
- Actual Result -
On single-core machine, this is tested to be true, one is using 97% and another is using 3% . but on dual-core machine,
nice utility does not seem to be working. no CPU usage has been reduced for the process which was created by using
nice. each one of them use the same amount of CPU time.
- Appendix : script used -
# load_generator.py import hashlib, binascii import random while True: dk = hashlib.pbkdf2_hmac('sha512', str(random.random())+str(random.random()), b'salt', 2000000) print(binascii.hexlify(dk))