≡ Menu

How To Stress Test CPU and Memory (VM) On a Linux and Unix With Stress-ng

I want test my Linux, OpenBSD, FreeBSD and Unix-like server entirely for high load and monitoring the health under stress. How can I stress out my CPU, memory, I/O, and disk stress and more with stress test tool on a Linux or Unix-like systems?

A sysadmin can try out any one of the following tool to put given subsytems under a specified load. Instances in which this is useful include those in which a system administrator wishes to perform tuning activities, a kernel or libc programmer wishes to evaluate denial of service possibilities, test your systems entirely on high load and monitoring the health, etc. This is also useful for sysadmin, system builders, and overclockers who want to test their hardware under high load and monitor stability and thermal environment.

  1. stress : It is a simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPLv2. It is not a benchmark, but is rather a tool designed
  2. stress-ng : It is an updated version of stress tool and it will stress test a server for the following features:
    1. CPU compute
    2. Cache thrashing
    3. Drive stress
    4. I/O syncs
    5. VM stress
    6. Socket stressing
    7. Context switching
    8. Process creation and termination
    9. It includes over 60 different stress tests, over 50 CPU specific stress tests that exercise floating point, integer, bit manipulation and control flow, over 20 virtual memory stress tests.

Warning: Running the following tools with root privileges is recommended to avoid out of memory and other errors. Also, note that tools will stress out your server resources quickly so use the following command judiciously.

Tool#1: Getting started with stress tool

This program is supposed to be easy to use and recommended for new sysadmins. The tool is known to work on x86 Linux and FreeBSD/OpenBSD, powerpc AIX and Linux, SPARC Solaris, Compaq Alpha Tru64 UNIX, and many others.

Install stress package

You can install stress as part of the distribution.

Install stress on a CentOS, RHEL, and Fedora Linux

First, turn on EPEL repo and then type the following yum command to install the same:

sudo yum install stress

Sample outputs:

Fig.01: Installing stress on a RHEL/CentOS/Fedora Linux

Fig.01: Installing stress on a RHEL/CentOS/Fedora Linux

Install stress on a Debian and Ubuntu Linux

Type the following apt-get command to install the same:

apt-get install stress

Sample outputs:

Fig.02: Install stress tool on a Debian/Ubuntu Linux

Fig.02: Install stress tool on a Debian/Ubuntu Linux

Install stress on a FreeBSD

Type the following pkg command to install the stress tool using binary method:

pkg install stress
## OR ##
pkg install sysutils/stress

Sample outputs:

Fig.03: FreeBSD installing stress tool

Fig.03: FreeBSD installing stress tool

Install stress on a OpenBSD

Type the following pkg_add command to install the stress tool using binary method:

export PKG_PATH=http://ftp.usa.openbsd.org/pub/OpenBSD/`uname -r`/packages/`arch -s`
pkg_add stress

How do I use stress tool?

First, note down the current system load averages by typing the following command:
# uptime
Next, run any one of the following command to see load on screen:
# watch uptime
OR use tload command:
# tload
The syntax is as follows:

stress [OPTION]
## Stress using CPU-bound task
stress -c 4
## Stress using IO-bound task 
stress -i 2

For example, a load average of four is imposed on the system by specifying two CPU-bound processes, one I/O-bound process, and one memory allocator process as follows:
# uptime
# stress -c 2 -i 1 -m 1 --vm-bytes 128M -t 10s
# uptime

Sample outputs:

Fig.04: A load average of four is imposed on the system

Fig.04: A load average of four is imposed on the system


Where,

  • -c 2 : Spawn two workers spinning on sqrt()
  • -i 1 : Spawn one worker spinning on sync()
  • -m 1 : Spawn one worker spinning on malloc()/free()
  • --vm-bytes 128M : Malloc 128MB per vm worker (default is 256MB)
  • -t 10s : Timeout after ten seconds
  • -v : Be verbose

Tool #2: Getting started with stress-ng

The stress-ng tool will stress test a computer system in various selectable ways.

Install stress-ng on a Linux or Unix-like systems

Type the following command to download stress-ng tarball using the wget command:
$ cd /tmp
$ wget http://kernel.ubuntu.com/~cking/tarballs/stress-ng/stress-ng-0.03.11.tar.gz

Untar tar ball, enter:
$ tar zxvf stress-ng-0.03.11.tar.gz
Compile stress-ng, run:
$ cd stress-ng-0.03.11
$ make

Sample outputs:

cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-affinity.o stress-affinity.c
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-aio.o stress-aio.c
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-bigheap.o stress-bigheap.c
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-brk.o stress-brk.c
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-bsearch.o stress-bsearch.c
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-cache.o stress-cache.c
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-chmod.o stress-chmod.c
....
..
cc -Wall -Wextra -DVERSION='"0.03.11"' -O2 -c -o stress-ng.o stress-ng.c
cc  -Wall -Wextra -DVERSION='"0.03.11"' -O2 stress-affinity.o stress-aio.o stress-bigheap.o stress-brk.o stress-bsearch.o stress-cache.o stress-chmod.o stress-clock.o stress-cpu.o stress-dentry.o stress-dir.o stress-dup.o stress-epoll.o stress-eventfd.o stress-fallocate.o stress-fault.o stress-fifo.o stress-flock.o stress-fork.o stress-fstat.o stress-futex.o stress-get.o stress-hdd.o stress-hsearch.o stress-inotify.o stress-iosync.o stress-kill.o stress-lease.o stress-lsearch.o stress-link.o stress-lockf.o stress-memcpy.o stress-mincore.o stress-mmap.o stress-msg.o stress-mq.o stress-nice.o stress-noop.o stress-null.o stress-open.o stress-pipe.o stress-poll.o stress-procfs.o stress-pthread.o stress-qsort.o stress-rdrand.o stress-rename.o stress-seek.o stress-sem.o stress-sendfile.o stress-sigfd.o stress-sigfpe.o stress-sigsegv.o stress-sigq.o stress-socket.o stress-stack.o stress-switch.o stress-sysinfo.o stress-timer.o stress-tsearch.o stress-urandom.o stress-utime.o stress-vm.o stress-wait.o stress-yield.o stress-zero.o coredump.o helper.o io-priority.o lock-mem.o log.o madvise.o mincore.o mounts.o mwc.o out-of-memory.o parse-opts.o proc-name.o sched.o time.o stress-ng.o -lm -lpthread -lrt -o stress-ng

How do I use the stress-ng tool?

The syntax is:

stress-ng [options]
stress-ng -c 2
stress-ng -c 4 -t 10 -v
stress-ng -c 4 --metrics-brief

Examples

To run for 60 seconds with 4 cpu stressors, 2 io stressors and 1 vm stressor using 1GB of virtual memory, enter:

stress-ng --cpu 4 --io 2 --vm 1 --vm-bytes 1G --timeout 60s --metrics-brief

Sample outputs:

Fig.05: stress-ng in action

Fig.05: stress-ng in action


In this example, run 16 cpu stressors and stops after 900000 bogo operations:

stress-ng --cpu 16 --cpu-ops 900000

To run 4 simultaneous instances of all the stressors sequentially one by one, each for 6 minutes and summaries with performance metrics at the end:

stress-ng --sequential 4 --timeout 6m --metrics

To run 2 FFT cpu stressors, stop after 5000 bogo operations and produce a summary just for the FFT results:

stress-ng --cpu 2 --cpu-method fft --cpu-ops 5000 --metrics−brief

To run cpu stressors on all online CPUs working through all the available CPU stressors for 2 hour:

stress−ng --cpu 0 --cpu-method all -t 2h

To run 2 instances of all the stressors for 10 minutes:

stress-ng --all 2 --timeout 10m

To run 128 stressors that are randomly chosen from all the available stressors:

stress-ng --random 128

To run 64 instances of all the different cpu stressors and verify that the computations are correct for 5 minutes with a bogo operations summary at the end:

stress-ng --cpu 64 --cpu−method all --verify -t 5m --metrics−brief

To run all the stressors one by one for 5 minutes, with the number of instances of each stressor matching the number of online CPUs:

stress-ng --sequential 0 -t 5m

To run all the stressors in the io class one by one for 1 minutes each, with 8 instances of each stressor running concurrently and show overall time utilisation statistics at the end of the run:

stress-ng --sequential 8 --class io -t 1m --times
References
Share this tutorial on:

{ 14 comments… add one }
  • Jari Luukkonen January 29, 2015, 10:05 am

    you got typo

    Install stress on a CentOS, RHEL, and Fedora Linux
    First, turn on EPEL repo and then type the following yum command to install the same:

    sudo yum install stree

    • nixCraft January 29, 2015, 11:10 am

      Thanks for the heads up!

      • cvillepete January 30, 2015, 1:27 pm

        There are a few typos. Sign me up to review your articles if you need help. ;)

  • Colin King January 29, 2015, 10:58 am

    Thanks for the write up on stress-ng. I am still adding more stress features to stress-ng, but it is now almost “feature complete”. If one has ideas for new stressors please let me know!

  • Starlight86 February 3, 2015, 2:26 pm

    Thumb up for the work. @Colin

  • gae December 21, 2015, 11:54 pm

    This script generates a controlled CPU load on the selected core. Pretty simple and scientific solution. https://github.com/GaetanoCarlucci/CPULoadGenerator

  • Jamal Schmidtman January 14, 2016, 4:23 pm

    Nice article. Used this to get stress installed on my Centos system.Thank you!

  • Marcos February 11, 2016, 4:45 pm

    Hi, which software did you use to make the “Fig.05: stress-ng in action”?

    I want to know hot to put arrows and comment in a image and all I know is using Paint-like softwares.

    Nice tutorial.

  • pratbid March 7, 2016, 11:29 am

    hey
    i need tools that could induce load on system CPU ,i/o etc in any platform. if you know please suggest me

  • Anthony March 15, 2016, 5:11 am

    I’m not seeing the package in the EPEL el7 repo.

    • Aaron July 9, 2016, 11:56 am

      Its in RepoForge in EL7
      http://repoforge.org/use/

      yum search stress
      — Output omitted
      stress.x86_64 : Tool to impose stress on a POSIX-compliant operating system
      fio.x86_64 : I/O benchmark and stress/hardware verification tool
      httpress.x86_64 : HTTP stress & benchmark utility

  • Ian June 9, 2016, 8:21 am

    To put load on the cpu without any third party tools:
    yes>/dev/null

Leave a Comment


   Tagged with: