How to Install ‘stress-ng’ Tool in Linux
To install stress-ng, run the following command.
$ sudo apt-get install stress-ng [on Debian based systems] # yum install stress-ng [on RedHat based systems]
The general syntax for using stress-ng is:
$ sudo stress-ng option argument
Some of the options that you can use with stress-ng:
- To start N instances of each stress test, use the –all N option as follows.
- To start N processes to exercises the CPU by sequentially working through all the different CPU stress testing methods, use the –cpu N option as follows.
- To use a given CPU stress testing method, use –cpu-method option. There are many methods available that you can use, to view the manpage to see all the methods to use.
- To stop CPU stress process after N bogo operations, use the –cpu-ops N option.
- To start N I/O stress testing processes, use the –io N option.
- To stop io stress processes after N bogo operations, use the –io-ops N option.
- To start N vm stress testing processes, use the –vm N option.
- To specify amount of memory per vm process, use –vm-bytes N option.
- To stop vm stress processes after N bogo operations, use –vm-ops N options
- Use the –hdd N option to start N harddisk exercising processes.
- To stop hdd stress processes after N bogo operations, use –hdd-ops N option.
- You can set a timeout after N seconds by using the –timeout N option.
- To generate a summary report after bogo operations, you can use –metrics or –metrics-brief options. The –metrics-brief displays non zero metrics.
- You can also start N processes that will create and remove directories using mkdir and rmdir by using the –dir N option.
- To stop directory operations processes use –dir-ops N options.
- To start N CPU consuming processes that will exercise the present nice levels, include the
- –nice N option. When using this option, every iteration will fork off a child process that runs through all the different nice levels running a busy loop for 0.1 seconds per level and then exits.
- To stop nice loops, use the –nice-ops N option as follows.
- To start N processes that change the file mode bits via chmod(2) and fchmod(2) on the same file, use the –chmod N option. Remember the greater the value for N then the more contention on the file. The stressor will work through all the combination of mode bits that you specify with chmod(2).
- You can stop chmod operations by the –chmod-ops N option.
- You can use the -v option to display more information about ongoing operations.
- Use -h to view help for stress-ng.
How Do I use ‘stress-ng’ in Linux systems?
1. To run 8 CPU stressors with a timeout of 60 seconds and a summary at the end of operations.
tecmint@tecmint:~$ uptime tecmint@tecmint:~$ sudo stress-ng --cpu 8 --timeout 60 --metrics-brief tecmint@tecmint:~$ uptime
Sample Output
tecmint@tecmint:~$ uptime 18:15:29 up 12 min, 1 user, load average: 0.00, 0.01, 0.03 [<-- Watch Load Average] tecmint@tecmint:~$ sudo stress-ng --cpu 8 --timeout 60 --metrics-brief stress-ng: info: [1247] dispatching hogs: 8 cpu stress-ng: info: [1247] successful run completed in 60.42s stress-ng: info: [1247] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s stress-ng: info: [1247] (secs) (secs) (secs) (real time) (usr+sys time) stress-ng: info: [1247] cpu 11835 60.32 59.75 0.05 196.20 197.91 tecmint@tecmint:~$ uptime 18:16:47 up 13 min, 1 user, load average: 4.75, 1.47, 0.54 [<-- Watch Load Average]
2. To run 4 FFT CPU stressors with a timeout of 2 minutes.
tecmint@tecmint:~$ uptime tecmint@tecmint:~$ sudo stress-ng --cpu 4 --cpu-method fft --timeout 2m tecmint@tecmint:~$ uptime
Sample Output
tecmint@tecmint:~$ uptime 18:25:26 up 22 min, 1 user, load average: 0.00, 0.26, 0.31 [<-- Watch Load Average] tecmint@tecmint:~$ sudo stress-ng --cpu 4 --cpu-method fft --timeout 2m stress-ng: info: [1281] dispatching hogs: 4 cpu stress-ng: info: [1281] successful run completed in 120.01s tecmint@tecmint:~$ uptime 18:27:31 up 24 min, 1 user, load average: 3.21, 1.49, 0.76 [<-- Watch Load Average]
3. To run 5 hdd stressors and stop after 100000 bogo operations, run this command.
tecmint@tecmint:~$ uptime tecmint@tecmint:~$ sudo stress-ng --hdd 5 --hdd-ops 100000 tecmint@tecmint:~$ uptime
Sample Output
tecmint@tecmint:~$ uptime 18:29:32 up 26 min, 1 user, load average: 0.43, 1.00, 0.67 [<-- Watch Load Average] tecmint@tecmint:~$ sudo stress-ng --hdd 5 --hdd-ops 100000 stress-ng: info: [1290] defaulting to a 86400 second run per stressor stress-ng: info: [1290] dispatching hogs: 5 hdd stress-ng: info: [1290] successful run completed in 136.16s tecmint@tecmint:~$ uptime 18:31:56 up 29 min, 1 user, load average: 4.24, 2.49, 1.28 [<-- Watch Load Average]
4. To run 8 CPU stressors, 4 I/O stressors and 1 virtual memory stressor using 1GB of virtual memory for one minute, run this command below.
tecmint@tecmint:~$ uptime tecmint@tecmint:~$ sudo stress-ng --cpu 4 --io 4 --vm 1 --vm-bytes 1G --timeout 60s --metrics-brief tecmint@tecmint:~$ uptime
Sample Output
tecmint@tecmint:~$ uptime 18:34:18 up 31 min, 1 user, load average: 0.41, 1.56, 1.10 [<-- Watch Load Average] tecmint@tecmint:~$ sudo stress-ng --cpu 4 --io 4 --vm 1 --vm-bytes 1G --timeout 60s --metrics-brief stress-ng: info: [1304] dispatching hogs: 4 cpu, 4 iosync, 1 vm stress-ng: info: [1304] successful run completed in 60.12s stress-ng: info: [1304] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s stress-ng: info: [1304] (secs) (secs) (secs) (real time) (usr+sys time) stress-ng: info: [1304] cpu 1501 60.07 2.67 10.39 24.99 114.93 stress-ng: info: [1304] iosync 381463 60.01 0.00 12.90 6357.10 29570.78 tecmint@tecmint:~$ uptime 18:35:36 up 32 min, 1 user, load average: 4.66, 2.80, 1.59 [<-- Watch Load Average]
Summary
As recommended, these tools should be used with superuser privileges as they have certain effects on the system. These tools are good for general System Administration in Linux. I hope this guide was useful and if you have any additional ideas on how to test the health status of your system using these tools or any other tools, do not hesitate to post a comment. Always stay connected to Tecmint, learn and share ideas for the benefit of open source.
Great stuff, but I’m wondering how can I put this stress test on my ESXi host without creating any new VM.
When I try to GPU burn test there are errors showing the:
gpu_burn-drv.cpp:in function int main(int, char**)
gpu_burn-drv.cpp:816:23: error: runtime_error is not a member of std throw std: : runtime_error("No cuda capable gpu found.\n)
But when I install ubuntu on the same server GPU burn test is ok so I can’t understand what is the issue so anyone tells me what to do……
I am using this stress-ng image and applying chaos at K8’s level as I am building chaos as a service. I am planning to put CPU stress. I was expecting the CPU % to spike > 80%. My hypothesis is similar to your uptime values ~ 1- 2% and when I apply CPU stress it is hardly spiking up to 10%. I tried various params but this is the max spike I get. Can we ever make CPU stress > 80% ? as I see even your load averages pretty low.
--vm-bytes
is NOT per vm worker but for all workers combined, so you can put almost all your memory if you boot without X.@Florian
Many thanks for the correction, we will cross check this.
Do we have this tool in freeBSD?
@Shashi,
Yes, you can install stress-ng tool on FreeBSD system to imposes certain types of high CPU Load on your FreeBSD based Unix system.
This stress-ng tool can be installed via ports as shown.
Just a tiny annoyance…
It’s “Spawn”, not “Spwan”
@JLockard,
Thanks for notifying about that typo, corrected in the writeup..
The article states: “It is highly recommended that you use these tools with root user privileges”. The manual does not recommend this:
Running stress-ng with root privileges will adjust out of memory set‐
tings on Linux systems to make the stressors unkillable in low memory
situations, so use this judiciously. With the appropriate privilege,
stress-ng can allow the ionice class and ionice levels to be adjusted,
again, this should be used with care.