The Stress tool is a command-line utility designed to intentionally overload a system, allowing developers and system administrators to perform stress testing and performance analysis. This tool is invaluable for understanding how a system behaves under heavy load, identifying potential bottlenecks, and ensuring stability.
To install the basic stress command on Debian-based
systems like Ubuntu, you can use the following command:
$ sudo apt install stress -y
The stress command allows you to specify the number of
CPU, I/O, and virtual memory workers, along with the duration of the
test. Here's an example of how to simulate a combined load:
$ stress --cpu 8 --io 4 --vm 4 --vm-bytes 1024M --timeout 10s
This command will attempt to stress 8 CPU cores, 4 I/O operations, and 4 virtual memory instances, each using 1024MB of memory, for a duration of 10 seconds.
For more comprehensive and advanced system stress testing, the
stress-ng utility is recommended. It offers a wider
range of stress tests and more granular control.
Install stress-ng using your package manager:
sudo apt install stress-ng -y
Use stress-ng to simulate CPU load across multiple
cores. You can adjust the --cpu parameter to match the
number of CPU cores you wish to stress:
# This command will stress 4 CPU cores for 60 seconds.
stress-ng --cpu 4 --timeout 60s
To simulate memory pressure, stress-ng can allocate
virtual machines. This command will allocate two virtual machines,
each consuming 1GB of memory, for 60 seconds:
# Adjust --vm and --vm-bytes to control memory stress.
stress-ng --vm 2 --vm-bytes 1G --timeout 60s
While stress-ng has I/O testing capabilities, the
dd command is a common and effective way to simulate
disk I/O load. The following command creates a 1GB test file and
synchronizes it to disk, stressing the I/O subsystem:
# This command creates a 1GB test file and stresses disk I/O.
dd if=/dev/zero of=/tmp/testfile bs=1M count=1024 conv=fdatasync
For more detailed information on system performance and load testing, consult resources like MDN Date Documentation or ISO 8601 Date and Time Format.