How to Test CPU and Memory Load with Stress & Stress-ng

In this article, I’ll install Stress on Linux machine and test CPU and memory load with Stress. Let’s get started:

Table of Contents

  1. Install Stress
  2. Run Stress
  3. Watch Load Average
  4. Note

Install Stress

Run this command to install Stress-ng (updated version of Stress):

# CentOS/RHEL 8
sudo dnf install stress-ng -y

# CentOS/REHL 7/Amazon Linux
sudo yum install stress-ng -y

# Debian/Ubuntu
sudo apt install stress-ng -y

Run this command to install Stress on your machine:

# CentOS/RHEL 8
sudo dnf install stress -y

# CentOS/REHL 7/Amazon Linux
sudo yum install stress -y

# Debian/Ubuntu
sudo apt install stress -y

Now run this command to see all available options:

stress-ng --help
# stress
stress --help

Run Stress

Stress using CPU-bound task:

stress-ng --cpu 4 -t 30s

# with stress
stress --cpu 4 -t 30s
#or
stress -c 4 -t 30s

Stress using IO-bound task:

stress-ng -i 4 -t 60s

# with stress
stress -i 4 -t 60s

We can run all of these tests in parallel by running the command below:

stress-ng --cpu 2 --all -t 120s

Give load using two CPU-bound processes, one I/O-bound process, and one memory allocator:

stress-ng -c 2 -i 1 -m 1 --vm-bytes 128M -t 20s

Watch Load Average

We can see the avegare load using these commands:

uptime
# or
watch uptime
# or
top

htop is another awesome tool to monitor loads:

# install htop
sudo yum install htop -y # CentOS/RHEL
sudo apt install htop -y # Debian/Ubuntu

# then run
htop

Note

If you run stress for a long time, you should reboot the system before making it live.

sudo reboot

That’s all. Thank you.