Chapter 35. Stress testing real-time systems with stress-ng
The stress-ng tool measures the system’s capability to maintain a good level of efficiency under unfavorable conditions. The stress-ng tool is a stress workload generator to load and stress all kernel interfaces. It includes a wide range of stress mechanisms known as stressors. Stress testing makes a machine work hard and trip hardware issues such as thermal overruns and operating system bugs that occur when a system is being overworked.
There are over 270 different tests. These include CPU specific tests that exercise floating point, integer, bit manipulation, control flow, and virtual memory tests.
Use the stress-ng tool with caution as some of the tests can impact the system’s thermal zone trip points on a poorly designed hardware. This can impact system performance and cause excessive system thrashing which can be difficult to stop.
35.1. Testing CPU floating point units and processor data cache Copy linkLink copied to clipboard!
A floating point unit is the functional part of the processor that performs floating point arithmetic operations. Floating point units handle mathematical operations and make floating numbers or decimal calculations simpler.
Using the --matrix-method option, you can stress test the CPU floating point operations and processor data cache.
Prerequisites
- You have root permissions on the systems
Procedure
To test the floating point on one CPU for 60 seconds, use the
--matrixoption:stress-ng --matrix 1 -t 1m
# stress-ng --matrix 1 -t 1mCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run multiple stressors on more than one CPUs for 60 seconds, use the
--timesor-toption:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The special mode with 0 stressors, query the available CPUs to run, removing the need to specify the CPU number.
The total CPU time required is 4 x 60 seconds (240 seconds), of which 0.13% is in the kernel, 85.50% is in user time, and
stress-ngruns 85.64% of all the CPUs.To test message passing between processes using a POSIX message queue, use the
-mqoption:stress-ng --mq 0 -t 30s --times --perf
# stress-ng --mq 0 -t 30s --times --perfCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
mqoption configures a specific number of processes to force context switches using the POSIX message queue. This stress test aims for low data cache misses.
35.2. Testing CPU with multiple stress mechanisms Copy linkLink copied to clipboard!
The stress-ng tool runs multiple stress tests. In the default mode, it runs the specified stressor mechanisms in parallel.
Prerequisites
- You have root privileges on the systems
Procedure
Run multiple instances of CPU stressors as follows:
stress-ng --cpu 2 --matrix 1 --mq 3 -t 5m
# stress-ng --cpu 2 --matrix 1 --mq 3 -t 5mCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the example,
stress-ngruns two instances of the CPU stressors, one instance of the matrix stressor and three instances of the message queue stressor to test for five minutes.To run all stress tests in parallel, use the
-alloption:stress-ng --all 2
# stress-ng --all 2Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example,
stress-ngruns two instances of all stress tests in parallel.To run each different stressor in a specific sequence, use the
--seqoption.stress-ng --seq 4 -t 20
# stress-ng --seq 4 -t 20Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example,
stress-ngruns all the stressors one by one for 20 minutes, with the number of instances of each stressor matching the number of online CPUs.To exclude specific stressors from a test run, use the
-xoption:stress-ng --seq 1 -x numa,matrix,hdd
# stress-ng --seq 1 -x numa,matrix,hddCopy to Clipboard Copied! Toggle word wrap Toggle overflow In this example,
stress-ngruns all stressors, one instance of each, excludingnuma,hddandkeystressors mechanisms.
35.3. Measuring CPU heat generation Copy linkLink copied to clipboard!
To measure the CPU heat generation, the specified stressors generate high temperatures for a short time duration to test the system’s cooling reliability and stability under maximum heat generation. Using the --matrix-size option, you can measure CPU temperatures in degrees Celsius over a short time duration.
Prerequisites
- You have root privileges on the system.
Procedure
To test the CPU behavior at high temperatures for a specified time duration, run the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the
stress-ngconfigures the processor package thermal zone to reach 88 degrees Celsius over the duration of 60 seconds.Optional: To print a report at the end of a run, use the
--tzoption:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
35.4. Measuring test outcomes with bogo operations Copy linkLink copied to clipboard!
The stress-ng tool can measure a stress test throughput by measuring the bogo operations per second. The size of a bogo operation depends on the stressor being run. The test outcomes are not precise, but they provide a rough estimate of the performance.
You must not use this measurement as an accurate benchmark metric. These estimates help to understand the system performance changes on different kernel versions or different compiler versions used to build stress-ng. Use the --metrics-brief option to display the total available bogo operations and the matrix stressor performance on your machine.
Prerequisites
- You have root privileges on the system.
Procedure
To measure test outcomes with bogo operations, use with the
--metrics-briefoption:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
--metrics-briefoption displays the test outcomes and the total real-time bogo operations run by thematrixstressor for 60 seconds.
35.5. Generating a virtual memory pressure Copy linkLink copied to clipboard!
When under memory pressure, the kernel starts writing pages out to swap. You can stress the virtual memory by using the --page-in option to force non-resident pages to swap back into the virtual memory. This causes the virtual machine to be heavily exercised. Using the --page-in option, you can enable this mode for the bigheap, mmap and virtual machine (vm) stressors. The --page-in option, touch allocated pages that are not in core, forcing them to page in.
Prerequisites
- You have root privileges on the system.
Procedure
To stress test a virtual memory, use the
--page-inoption:stress-ng --vm 2 --vm-bytes 2G --mmap 2 --mmap-bytes 2G --page-in
# stress-ng --vm 2 --vm-bytes 2G --mmap 2 --mmap-bytes 2G --page-inCopy to Clipboard Copied! Toggle word wrap Toggle overflow In this example,
stress-ngtests memory pressure on a system with 4GB of memory, which is less than the allocated buffer sizes, 2 x 2GB ofvmstressor and 2 x 2GB ofmmapstressor with--page-inenabled.
35.6. Testing large interrupts loads on a device Copy linkLink copied to clipboard!
Running timers at high frequency can generate a large interrupt load. The -timer stressor with an appropriately selected timer frequency can force many interrupts per second.
Prerequisites
- You have root permissions on the system.
Procedure
To generate an interrupt load, use the
--timeroption:stress-ng --timer 32 --timer-freq 1000000
# stress-ng --timer 32 --timer-freq 1000000Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example,
stress-ngtests 32 instances at 1MHz.
35.7. Generating major page faults in a program Copy linkLink copied to clipboard!
With stress-ng, you can test and analyze the page fault rate by generating major page faults in a page that are not loaded in the memory. On new kernel versions, the userfaultfd mechanism notifies the fault finding threads about the page faults in the virtual memory layout of a process.
Prerequisites
- You have root permissions on the system.
Procedure
To generate major page faults on early kernel versions, use:
stress-ng --fault 0 --perf -t 1m
# stress-ng --fault 0 --perf -t 1mCopy to Clipboard Copied! Toggle word wrap Toggle overflow To generate major page faults on new kernel versions, use:
stress-ng --userfaultfd 0 --perf -t 1m
# stress-ng --userfaultfd 0 --perf -t 1mCopy to Clipboard Copied! Toggle word wrap Toggle overflow
35.8. Viewing CPU stress test mechanisms Copy linkLink copied to clipboard!
The CPU stress test contains methods to exercise a CPU. You can print an output to view all methods using the which option.
If you do not specify the test method, by default, the stressor checks all the stressors in a round-robin fashion to test the CPU with each stressor.
Prerequisites
- You have root permissions on the system.
Procedure
Print all available stressor mechanisms, use the
whichoption:stress-ng --cpu-method which
# stress-ng --cpu-method which cpu-method must be one of: all ackermann bitops callfunc cdouble cfloat clongdouble correlate crc16 decimal32 decimal64 decimal128 dither djb2a double euler explog fft fibonacci float fnv1a gamma gcd gray hamming hanoi hyperbolic idct int128 int64 int32Copy to Clipboard Copied! Toggle word wrap Toggle overflow Specify a specific CPU stress method using the
--cpu-methodoption:stress-ng --cpu 1 --cpu-method fft -t 1m
# stress-ng --cpu 1 --cpu-method fft -t 1mCopy to Clipboard Copied! Toggle word wrap Toggle overflow
35.9. Using the verify mode Copy linkLink copied to clipboard!
The verify mode validates the results when a test is active. It sanity checks the memory contents from a test run and reports any unexpected failures.
All stressors do not have the verify mode and enabling one will reduce the bogo operation statistics because of the extra verification step being run in this mode.
Prerequisites
- You have root permissions on the system.
Procedure
To validate a stress test results, use the
--verifyoption:stress-ng --vm 1 --vm-bytes 2G --verify -v
# stress-ng --vm 1 --vm-bytes 2G --verify -vCopy to Clipboard Copied! Toggle word wrap Toggle overflow In this example,
stress-ngprints the output for an exhaustive memory check on a virtually mapped memory using thevmstressor configured with--verifymode. It sanity checks the read and write results on the memory.