How to increase CPU Utilization in Linux (CPU Spike)

There are scenarios, Where we need to test or replicate an issue in the cluster, which requires a CPU spike

For Me: I wanted to create a CPU spike to test AWS auto-scaling based on CPU utilization

Below are the two easy ways to create the CPU spike that I have used.

Using Stress utility

Stress is a utility designed to simulate CPU stress

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install Stress utility in Linux

sudo yum install stress -y

confirming the installation

Once the installation is done, We can proceed to use the tool to create stress in the CPU

stress –cpu 9 –timeout 300

CPU N -> N workers spinning. Above will use 9 cores for 300 sec

increase CPU Utilization in Linux (CPU Spike)

These can be tuned based on the capacity

Use the “yes” command

“yes” command will repeatedly print the string, which is passed as an argument, causing a spike in CPU utilization. We can run multiple yes commands to max out cores.

yes > /dev/null

directly to “/dev/null” to make sure it is not printing on the console screen.

Good luck with your learning, Let us know if you have any other methods to max the CPU

Similar Posts