How to Impose High CPU Load and Stress Test on Linux Using ‘Stress-ng’ Tool

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]

Install stress-ng in Debian

The general syntax for using stress-ng is:

$ sudo stress-ng option argument

Some of the options that you can use with stress-ng:

  1. To start N instances of each stress test, use the –all N option as follows.
  2. 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.
  3. 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.
  4. To stop CPU stress process after N bogo operations, use the –cpu-ops N option.
  5. To start N I/O stress testing processes, use the –io N option.
  6. To stop io stress processes after N bogo operations, use the –io-ops N option.
  7. To start N vm stress testing processes, use the –vm N option.
  8. To specify amount of memory per vm process, use –vm-bytes N option.
  9. To stop vm stress processes after N bogo operations, use –vm-ops N options
  10. Use the –hdd N option to start N harddisk exercising processes.
  11. To stop hdd stress processes after N bogo operations, use –hdd-ops N option.
  12. You can set a timeout after N seconds by using the –timeout N option.
  13. To generate a summary report after bogo operations, you can use –metrics or –metrics-brief options. The –metrics-brief displays non zero metrics.
  14. You can also start N processes that will create and remove directories using mkdir and rmdir by using the –dir N option.
  15. To stop directory operations processes use –dir-ops N options.
  16. To start N CPU consuming processes that will exercise the present nice levels, include the
  17. –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.
  18. To stop nice loops, use the –nice-ops N option as follows.
  19. 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).
  20. You can stop chmod operations by the –chmod-ops N option.
  21. You can use the -v option to display more information about ongoing operations.
  22. 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.

[email protected]:~$ uptime
[email protected]:~$ sudo stress-ng --cpu 8 --timeout 60 --metrics-brief
[email protected]:~$ uptime
Sample Output
[email protected]:~$ uptime
 18:15:29 up 12 min,  1 user,  load average: 0.00, 0.01, 0.03     [<-- Watch Load Average]
[email protected]:~$ 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
[email protected]:~$ 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.

[email protected]:~$ uptime
[email protected]:~$ sudo stress-ng --cpu 4 --cpu-method fft --timeout 2m
[email protected]:~$ uptime
Sample Output
[email protected]:~$ uptime
 18:25:26 up 22 min,  1 user,  load average: 0.00, 0.26, 0.31     [<-- Watch Load Average]
[email protected]:~$ 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
[email protected]:~$ 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.

[email protected]:~$ uptime
[email protected]:~$ sudo stress-ng --hdd 5 --hdd-ops 100000
[email protected]:~$ uptime
Sample Output
[email protected]:~$ uptime
 18:29:32 up 26 min,  1 user,  load average: 0.43, 1.00, 0.67     [<-- Watch Load Average] 
[email protected]:~$ 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
[email protected]:~$ 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.

[email protected]:~$ uptime
[email protected]:~$ sudo stress-ng --cpu 4 --io 4 --vm 1 --vm-bytes 1G --timeout 60s --metrics-brief
[email protected]:~$ uptime
Sample Output
[email protected]:~$ uptime
 18:34:18 up 31 min,  1 user,  load average: 0.41, 1.56, 1.10     [<-- Watch Load Average]
[email protected]:~$ 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
[email protected]:~$ 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.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

8 thoughts on “How to Impose High CPU Load and Stress Test on Linux Using ‘Stress-ng’ Tool”

  1. 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.

    Reply
  2. --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.

    Reply
    • @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.

      # cd /usr/ports/sysutils/stress/
      # make install clean
      # pkg install sysutils/stress
      
      Reply
  3. 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.

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.