Razique Mahroua
2019-12-11 24e00434ed2bae853e25f57eaf0ff630fc182fc8
Add an application to load the CPU & memory
2 files added
51 ■■■■■ changed files
python-load/Dockerfile 15 ●●●●● patch | view | raw | blame | history
python-load/load.py 36 ●●●●● patch | view | raw | blame | history
python-load/Dockerfile
New file
@@ -0,0 +1,15 @@
FROM registry.access.redhat.com/ubi8/python-36:latest
LABEL version="1.0" \
  description="Application for stressing the system" \
  creationDate="2019-12-10" \
  updatedDate="2019-12-28"
USER 0
RUN pip3 install numpy
ADD load.py $HOME/
ENTRYPOINT [ "python3", "./load.py" ]
USER 1001
python-load/load.py
New file
@@ -0,0 +1,36 @@
#!/usr/bin/python3
"""
Produces load on all available CPU cores
Updated with suggestion to prevent Zombie processes
Linted for Python 3
Source:
insaner @ https://danielflannery.ie/simulate-cpu-load-with-python/#comment-34130
"""
import numpy
from multiprocessing import Pool
from multiprocessing import cpu_count
import signal
# Change the xrange (allocation) value accordingly.
allocation = 4096
stop_loop = 0
def exit_chld(x, y):
    global stop_loop
    stop_loop = 1
def f(x):
    global stop_loop
    while not stop_loop:
        x*x
        [numpy.random.bytes(1024*1024) for x in range(allocation)]
signal.signal(signal.SIGINT, exit_chld)
if __name__ == '__main__':
    processes = cpu_count()
    print('-' * 20)
    print('Running load on CPU(s)')
    print('Utilizing %d cores' % processes)
    print('-' * 20)
    pool = Pool(processes)
    pool.map(f, range(processes))