If you’re looking to simulate high CPU usage for load testing or monitoring purposes on an Ubuntu Server, you can use the stress tool. Below is a streamlined, beginner-friendly guide to help you set this up with live CPU monitoring in your terminal.
Begin by updating your package list to ensure you get the latest versions:
sudo apt-get update
Install the stress utility, which is specifically designed for load testing:
sudo apt-get install stressIf you want to monitor your load and keep the session running even after disconnecting, start a tmux session:
tmux
Open the system monitoring dashboard using the top command. This will help you visualize CPU usage in real time:
top
In a new terminal window (or tmux pane), run the following command to increase CPU utilization (replace 5 with the number of CPU cores you want to stress):
stress -c 5
This command will fully utilize five CPU cores, effectively pushing overall CPU usage toward 100% (depending on your server’s core count).
Adjust the -c flag to match the number of CPU cores you want to stress.
Use Ctrl+C to stop the stress test at any time.
Combine this setup with monitoring tools like htop or your cloud provider’s resource dashboard for deeper insights.
This approach is ideal for testing performance, stability, or auto-scaling behavior in a safe and controlled environment.