How to Impose High CPU Load and Stress Test on Linux?
In this section, we will see how we can impose a High CPU Load and Stress Test on Linux with different options. We will see various examples with each example having different options and flags included:
Example 1: Imposing High CPU Load
Stress-ng also gives us a multitude of settings with which you can stress various components in our system.
Syntax:
stress-ng --cpu <number_of_cpus> --timeout <duration_in_seconds>
stress-ng
: The command itself, indicating the use of the stress-ng tool.-
-cpu <number_of_cpus>
: Specifies the CPU stress test, where<number_of_cpus>
the desired number of CPU workers to stress.--timeout <duration_in_seconds>
: Sets a time limit for the stress test,<duration_in_seconds>
representing the duration for which the stress test should run.
Command:
Now, we need to replace <number of cpus> with the desired number of CPU workers and <duration in seconds> with the duration for which we want the test to run.
stress-ng --cpu 0 --timeout 60s
Output:
The –cpu 0 option states that we are using all the available CPUs. We can specify the CPU frequency by adjusting the –cpu option value
Example 2: To stress a specific percentage of CPU
This parameter is used to implement the specific percentage of stress on the system.
Syntax:
stress-ng --cpu-load <percentage> --timeout <duration_in_seconds>
stress-ng
: The main command for invoking the stress-ng tool.--cpu-load <percentage>
: Specifies the percentage of CPU load to be generated. Replace<percentage>
with the desired value, such as 50 for 50% CPU load.--timeout <duration_in_seconds>
: Sets the duration for which the stress-ng tool will run, inducing the specified stress. Replace<duration_in_seconds>
with the desired duration in seconds.
Command:
Replace <percentage> with the desired CPU load percentage. For instance, to stress the CPU at 80% for 10 minutes:
stress-ng --cpu-load 80 --timeout 60s
Output:
Example 3: Sequential CPU Stress with Timeout
In this example, we will perform sequential CPU stress with a timeout parameter.
Syntax:
stress-ng --cpu <number_of_cpus> --timeout <duration_in_seconds> --sequential
stress-ng
: The main command for invoking the stress-ng tool.--cpu <number_of_cpus>
: Specifies the number of CPUs to stress. Replace<number_of_cpus>
with the desired number of CPUs. For example,--cpu 4
to stress 4 CPUs.--timeout <duration_in_seconds>
: Sets the duration for which the stress-ng tool will run, inducing the specified stress. Replace<duration_in_seconds>
with the desired duration in seconds.--sequential
: Indicates that the stress-ng workload will be applied sequentially.
Command:
To sequentially stress each CPU for 2 minutes, you can use the following command:
stress-ng --cpu 0 --timeout 120s --sequential 3
It involves –sequential as an option which makes sure stress-ng stresses each CPU sequentially, one by one, and timeout determines the time of stress testing in the system.
Output:
Example 4: Custom CPU Stress Method
In this example, we will perform custom CPU stress.
Syntax & Command:
If you want to stress all components of the system simultaneously (CPU, memory, I/O, etc.), you can use the ‘–all‘ option:
stress-ng --all --timeout 60s
stress-ng
: The main command for invoking the stress-ng tool.--all
: Specifies that stress should be applied to all available stressors. This includes CPU, memory, I/O, and other stressors depending on the system.--timeout 240s
: Sets the duration for which the stress-ng tool will run. In this case, it’s set to 240 seconds (4 minutes).
This stresses numerous components in the system, serving as an overall or total stress test.
Output:
Example 5: Random Stress with Timeout
In this example, we will perform random stress with a timeout parameter.
Syntax & Command:
For a random combination of stressors with a timeout of 4 minutes, use the command mentioned below:
stress-ng --random 1 --timeout 60s
stress-ng
: The main command for invoking the stress-ng tool.--random 1
: Specifies the use of random stressors. The1
indicates the number of stressors, and in this case, it’s set to 1 random stressor.--timeout 240s
: Sets the duration for which the stress-ng tool will run. In this case, it’s set to 240 seconds (4 minutes).
The –random is a very flexible stressing parameter that can be applied to a mixture of different stress factors.
Output:
How to Impose High CPU Load and Stress Test on Linux Using ‘Stress-ng’ Tool
The system must have the capacity to handle a high workload regarding systems administration activities including performance testing. One such method used in testing the robustness of a system at its limit points is known as stress testing. Stress-ng is also a great versatile and strong tool for stress testing. This article is aimed at providing instructions on how to set up to overstress a Linux system or high-CPU load.
Contact Us