Master Linux Stress Testing with stress‑ng: Install, Commands & Real‑World Scenarios
This guide introduces the stress‑ng tool, explains how to install it via yum or from source, details its command‑line options, and provides step‑by‑step examples for CPU, memory, I/O, and disk stress tests with monitoring commands and result screenshots.
Stress‑ng Tool Overview
stress‑ng is a powerful Linux stress‑testing utility that can generate load on various system resources such as CPU, disk, network, memory, processes, and file systems. It extends the original stress tool with many more stressors and supports fine‑grained control of test intensity and duration.
Installation
1. yum installation (quick but may not be the latest version)
yum install -y epel-release.noarch && yum -y update yum install -y stress stress-ng2. Source installation (recommended for the newest release)
Download the latest source package, extract it, compile and install:
wget https://fossies.org/linux/privat/stress-ng-0.16.03.tar.gz tar -xzf stress-ng-0.16.03.tar.gz cd stress-ng-0.16.03 make && make installAfter a successful build, verify the installation:
stress-ng -VCommand Usage and Common Options
stress-ng [OPTION [ARG]]Key options include:
-h, --help Show help information
--version Show version information
-t, --timeout SECS Run for the specified number of seconds
-c, --cpu N Spawn N workers that repeatedly call sqrt() to stress CPU
-i, --io N Spawn N workers that repeatedly call sync() to stress I/O
-m, --vm N Spawn N workers that allocate/free memory to stress RAM
-d, --hdd N Spawn N workers that perform write/unlink operations
--cpu-method METHOD Choose a specific CPU stress method
--metrics Output execution metrics
--vm-bytes BYTES Size of each memory allocation (default 256M)
--class CLASS Select a class of stressors
--matrix MODE Enable matrix test mode
--random-seed SEED Set random seed for reproducibility
--sequential Enable sequential test mode
--hdd-bytes BYTES Amount of data each HDD worker writes
--cpu-load PERCENT Target CPU load percentagePractical Stress‑Testing Scenarios
1. CPU Load Test
Run four CPU workers using the matrix multiplication stressor for 600 seconds:
stress-ng --cpu 4 --cpu-method matrixprod --timeout 600sMonitor the system before and during the test with top (screenshots omitted for brevity).
2. Memory Load Test
Allocate 512 MiB in each of four workers, keep the allocation for 600 seconds: stress-ng --vm 4 --vm-bytes 512M --timeout 600s Check memory usage with free and top before and during the test.
3. I/O Load Test
Spawn four I/O workers for a 600‑second test: stress-ng --io 4 --timeout 600s Observe disk activity using top and a Prometheus monitoring setup.
4. Disk Write Test
Use one HDD worker to write 1000 MiB blocks with four I/O workers for 600 seconds:
stress-ng --io 4 --hdd 1 --hdd-bytes 1000M --timeout 600s5. Combined CPU and I/O Test
Run four CPU workers and two I/O workers simultaneously for 600 seconds:
stress-ng --cpu 4 -i 2 --timeout 600s6. Adjusted CPU Load Percentage
Test four CPU workers with a target load of 60 % for 600 seconds: stress-ng --cpu 4 --cpu-load 60 --timeout 600s During all scenarios, use top (or Prometheus) to capture real‑time load metrics and verify that the intended stress level is achieved.
Conclusion
stress‑ng provides a rich set of options for generating realistic load on Linux systems. By selecting appropriate stressors and parameters, you can simulate CPU, memory, I/O, and disk pressure, monitor the impact with standard tools, and fine‑tune the intensity to match testing requirements.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
