stress
Stress test system resources
TLDR
Spawn 4 workers to stress test CPU
Spawn 2 workers to stress test IO and timeout after 5 seconds
Spawn 2 workers to stress test memory (each worker allocates 256M bytes)
Spawn 2 workers spinning on write()/unlink() (each worker writes 1G bytes)
SYNOPSIS
stress [options]
PARAMETERS
-c N, --cpu N
Creates N worker processes that loop on sqrt(random()), consuming CPU cycles.
-i N, --io N
Creates N worker processes that call sync() to force disk I/O, causing high I/O wait.
-m N, --vm N
Creates N worker processes that continually allocate and free memory (malloc/free).
--vm-bytes B
Specifies the amount of memory each --vm worker allocates. Can use suffixes like B, K, M, G (e.g., 256M).
--vm-hang N
Specifies for how long, in seconds, each --vm worker sleeps after allocating memory before freeing it.
--vm-keep
Instructs --vm workers not to free memory after allocation, keeping the memory allocated indefinitely until the worker exits.
-d N, --hdd N
Creates N worker processes that write and read temporary files, generating disk I/O.
--hdd-bytes B
Specifies the amount of disk space each --hdd worker uses for its temporary files. Can use suffixes like B, K, M, G.
--hdd-no-sync
Prevents the fsync() system call for --hdd workers, which can make I/O faster but less robust against power failure.
-t N, --timeout N
Specifies the duration of the test in seconds. stress will automatically exit after N seconds.
--backoff N
Pauses for N seconds before starting any workers. Useful for staggered tests or delaying the load.
-q, --quiet
Suppresses non-error messages, showing only critical output.
-v, --verbose
Displays more detailed messages, useful for debugging.
--version
Shows program version and exits.
-h, --help
Displays a help message and exits.
DESCRIPTION
stress is a simple yet powerful utility designed to impose a configurable workload on a Linux system. Its primary purpose is to test the stability and performance of hardware and software under various load conditions.
It achieves this by creating child processes or threads that continuously consume specific system resources: CPU cycles, memory allocation (including optional swapping), disk I/O operations (writing and reading files), and pipe I/O.
Administrators and developers often use stress for benchmarking, identifying system bottlenecks, verifying system stability after hardware or software changes, and debugging performance issues. Users can specify the number of workers for each resource type and set a duration for the stress test, making it a versatile tool for quick system assessments.
CAVEATS
Caution: Running stress can significantly impact system performance, potentially leading to unresponsiveness or crashes, especially if not monitored properly. Use with extreme care on production or critical systems.
The load generated by stress is synthetic and may not perfectly mimic real-world application workloads, so results should be interpreted accordingly.
EXAMPLES
1. Stressing CPU and Memory:
stress -c 4 -m 1 --vm-bytes 512M -t 60
This command runs 4 CPU-bound processes and 1 memory-bound process (each allocating 512MB) for 60 seconds.
2. Stressing Disk I/O:
stress -d 2 --hdd-bytes 1G -t 300
This runs 2 disk I/O workers, each using 1GB of temporary file space, for 300 seconds.
3. Running Multiple Stressors Simultaneously:
stress --cpu 2 --io 1 --vm 1 --hdd 1 --timeout 120
This simultaneously stresses CPU, I/O, memory, and disk with a specified number of workers for 120 seconds.
EXIT STATUS
stress exits with status 0 on success, or a non-zero status if an error occurs (e.g., failed to fork, invalid arguments) or if the timeout is reached before all workers complete their tasks successfully.
HISTORY
stress was originally developed by Amos Waterland as a straightforward utility to impose configurable load on a system. It quickly became a common tool for basic system stability testing and benchmarking due to its simplicity and effectiveness.
While more sophisticated tools like stress-ng have emerged, offering a wider array of stress mechanisms and finer control, the original stress command remains popular for quick and essential load generation tasks in various Linux environments.