Generate artificial load on CPU by running two configurable loops, one nested inside the other.
263
The container generates artificial load upon the CPU. It runs two trivial loops, one nested inside the other. The internal (inner/nested) loop iterates a floating-point multiplication operation intIter times. The outer loop runs the inner one and after the inner loop finishes its last iteration the outer loop pauses for time duration tsleep and runs the inner loop again. The outer loop can operate in one of two modes. In the time-controlled mode executing the sequence of inner loop and sleep time is repeated until the total duration of the run exceeds a predefined threshold. In iteration-controlled mode executing the sequence of inner loop and sleep time is repeated until the number of repetitions reaches a predefined threshold. Desired mode and threshold are provided to the container as a (compound) argument with the syntax defined below. One can tune load characteristics of the container (the average CPU load and load burstiness) by experimentally choosing the value of the parameters mentioned (intIter, tsleep, mode/threshold). The image has been used for generating workloads in kubernetes clusters to test congestion control strategies.
$ docker run --name <some-name> -d dburszty/artificial-workload-amd64:latest -c <intIter> <tsleep> <mode>=<threshold>
where:
<intIter> ::= <integer>
<tsleep> ::= <float> ; interpreted as [milliseconds]
<mode> ::= otime | oiter
<threshold> ::= <float> | <integer> ; interpreted according to the value of <mode>
with the following constraints/interpretation for the outer loop:
if <mode> == otime then <threshold> ::= <float> ; interpreted as duration [seconds]
if <mode> == oiter then <threshold> ::= <integer> ; interpreted as the number of iterations
iterate the inner loop for approx. 60 seconds:
$ docker run --name testload -d dburszty/artificial-workload-amd64:latest -c 10000 5 otime=60
$ kubectl run -n $NAMESPACE $PODNAME --image=dburszty/artificial-workload-amd64:latest --restart=Never -- 10000 5 otime=60
iterate the inner loop 10000 times:
$ docker run --name testload -d dburszty/artificial-workload-amd64:latest -c 10000 5 oiter=10000
$ kubectl run -n $NAMESPACE $PODNAME --image=dburszty/artificial-workload-amd64:latest --restart=Never -- 10000 5 oiter=10000
It's up to the user's decision to additionally set docker-specific paramaters as, e.g., cpu-period or cpu-shares, or resource limits in Kubernetes.
The following default settings apply:
INT_ITER = 10000, the default number of inner loop iterations
T_SLEEP = 5, the default time in [milliseconds] to sleep after one complete inner loop run
LIFE_TIME = 60, the default time duration of the outer loop in [seconds] (i.e., the expected life time of the process/container)
TIME_LOOP = True, indicates that the outer loop has to be time-controlled, and if False then the loop has to be iteration-controlled
$ docker ... -c 10000 5 otime=60
This will result in approximately 100 outer loop iterations per second and will consume around 18% of single core capacity on Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz. For arm64v8 BCM2837 processor on Raspberry Pi CM3+ in Kubernetes environment and similar settings the container will consume around 55% of single core capacity. Note: these figures are only rough estimates and are based on visual task manager and Prometheus/Grafana observations, respectively.
Content type
Image
Digest
sha256:ebe258670…
Size
17.7 MB
Last updated
over 2 years ago
docker pull dburszty/artificial-workload-amd64