A sysadmin can try out any one of the following tool to put given subsytems under a specified load.[donotprint][/donotprint]One can stress test CPU on Linux other subsystem. 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 and more. 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.
Tools To Stress Test CPU and Memory (VM) On a Linux / Unix
- 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
- stress-ng : It is an updated version of stress tool and it will stress test a server for the following features:
- CPU compute
- Cache thrashing
- Drive stress
- I/O syncs
- VM stress
- Socket stressing
- Context switching
- Process creation and termination
- 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.
Getting started with stress tool on Linux
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 on a Linux
You can install stress as part of the Linux or Unix distribution.
Install stress on a CentOS, RHEL, and Fedora Linux
Install stress on a Debian and Ubuntu Linux
Type the following apt-get command to install the same:
apt-get install stress
Install stress on a FreeBSD Unix system
Type the following pkg command to install the stress tool using binary method:
pkg install stress ## OR ## pkg install sysutils/stress
Install stress on a OpenBSD Unix system
Type the following pkg_add command to install the stress tool using binary method:
## if installpath not set in /etc/pkg.conf as follow ## ## installpath = http://mirror.esc7.net/pub/OpenBSD/%c/packages/%a/ use ## ## PKG_PATH ## export PKG_PATH=http://ftp.usa.openbsd.org/pub/OpenBSD/`uname -r`/packages/`arch -s` pkg_add stress
How do I use stress tool on Linux?
First, note down the current system load averages by typing the following command:
Next, run any one of the following command to see load on screen:
# watch uptime
OR use tload command:
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:
# stress -c 2 -i 1 -m 1 --vm-bytes 128M -t 10s
- -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
Getting started with stress-ng on Linux and Unix
The stress-ng tool will stress test a Linux 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.09.34.tar.xz
Untar tar ball, enter:
$ tar xvf stress-ng-0.09.34.tar.xz
Compile stress-ng, run:
$ cd stress-ng-0.09.34
make -f Makefile.config make: Entering directory '/tmp/stress-ng-0.09.34' autoconfig: using -lcrypt autoconfig: using pthread spinlock autoconfig: using -lrt autoconfig: using -lz autoconfig: using -ldl autoconfig: using -lpthread autoconfig: using wchar.h autoconfig: using grp.h autoconfig: using sys/xattr.h autoconfig: using sys/syscall.h ..... ... ..... CC mwc.c CC parse-opts.c CC out-of-memory.c CC net.c CC sched.c CC setting.c CC thermal-zone.c CC shim.c CC perf.c CC thrash.c CC time.c CC stress-ng.c CC stress-personality.c LD stress-ng make: Leaving directory '/tmp/stress-ng-0.09.34'
You can also install it using snap command or apt-get command:
$ sudo apt install stress-ng
How do I use the stress-ng tool on Linux?
The syntax is:
stress-ng [options] stress-ng -c 2 stress-ng -c 4 -t 10 -v stress-ng -c 4 --metrics-brief
Always note down the output of uptime command before starting it:
Let us see some examples of stress-ng.
Unix / Linux cpu stress test
Let us start N workers exercising the CPU by sequentially working through all the different CPU stress methods:
stress-ng --cpu 4 --timeout 60s --metrics-brief
Unix / Linux cpu stress test
For disk start N workers continually writing, reading and removing temporary files:
stress-ng --disk 2 --timeout 60s --metrics-brief
One can pass the --io N option to the stress-ng command to commit buffer cache to disk:
stress-ng --disk 2 --io 2 --timeout 60s --metrics-brief
Unix / Linux memory stress test
Let us populate memory. Use mmap N bytes per vm worker, the default is 256MB. One can specify the size as % of total available memory or in units of Bytes, KBytes, MBytes and GBytes using the suffix b, k, m or g:
stress-ng --vm 2 --vm-bytes 1G --timeout 60s
The --vm 2 will start N workers (2 workers) continuously calling mmap/munmap and writing to the allocated memory. Note that this can cause systems to trip the kernel OOM killer on Linux systems if not enough physical memory and swap is not available.
Putting it all together
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
In this example, run 16 cpu stressors and stops after 900000 bogo operations:
stress-ng --cpu 16 --cpu-ops 900000
stress-ng --cpu 16 --cpu-ops 900000 --timeout 16
stress-ng: info:  dispatching hogs: 16 cpu stress-ng: info:  successful run completed in 60.17s (1 min, 0.17 secs)
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
Should I run stess-ng with root access?
From the man page:
Running stress-ng with root privileges will adjust out of memory settings 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. However, some options do requires root privilege to alter various /sys interface controls. See stess-ng command man page for more info.
You just learned how to use the stess and stress-ng command to impose high CPU load on Linux and Unix-like system.
- Linux and Unix Test Disk I/O Performance With dd Command
- stress home page – Download source code and docs.
- stress-ng home page– Download source code and docs.