I have been working on the docker auto-scaling stuff, and got the need of container which could stress the CPU
In Linux, there is stress utility which would stress the CPU, simple and sweet. Now, I need to put this stress utility on container and all get to go. Quick google got me few containers on docker hub, which were already build for this job, Great!
But, I had problems with these. First, they would start stressing the CPU as soon they start, this is not what I need in my scenario. Secondly, I can’t fire command remotely, i.e. out container and docker host, I don’t have control on when to start, how much CPU to stress and how much time I should let them run
There is another utility, lookbusy, which let me control how much CPU percentage I want to stress. It was important for me, a utility which gives me control on the CPU percentage, say 70% load unlike stress utility, where I need to do trial and error to find what number would stress my CPU to 70%
Second, I had these container running behind a load balancer. I got an idea, where I could simply develop python Flask web app. This would serve Web UI where I could mention the percentage of CPU and time to stress, and in the hood it would use lookbusy to stress the CPU. This away, even without accessing the docker host, I can stress host CPU remotely from a browser.
You can start the container with following command
docker run -p 80:5000 -name stressor sbrakl/stressor
Here, if port 80 is used by other application, you chose whatever available on your machine, say 5000.
This container run flask app on port 5000.
Now, this come in three flavours
Flask stress app running on Werkzeug web server. It good for light weight concurrent loads, but bad for 5+ concurrent load
Same as flaskappwithWerkzeug, but configure to run on SSL. It useful in scenarios, where you need to configure containers behind load balancer. This will test load balancer for SSL traffic.
Flask app is configure to run on the uwsgi and nginx webserver. It configure to run 16 concurrent request.
You can find more information about configuration on Github repository