Files
my-docs/Monitoring-Logging/Tools/stress-ng.md

3.9 KiB
Raw Permalink Blame History

Stress-ng: Hardware Stress Testing Tool

stress-ng is a powerful tool for performing various stress tests on your hardware components, including CPU, memory, and I/O. This utility helps in assessing hardware stability under heavy loads, making it useful for benchmarking or diagnosing hardware issues.

Table of Contents

Installation

To install stress-ng on Ubuntu or other Debian-based systems, run:

sudo apt install stress-ng

CPU Stress Testing

Use stress-ng to test CPU performance under different configurations:

1. Run a CPU Test with a Specified Number of Threads

You can specify the number of threads to use during a CPU stress test. Using 0 as the thread number utilizes all available CPU cores, maximizing CPU usage.

stress-ng --cpu <thread-number>

Example:

stress-ng --cpu 4

This command uses 4 CPU threads to run the stress test.

2. Run a CPU Test for a Specified Duration

Specify both the number of CPU threads and a time limit for the test.

stress-ng --cpu <thread-number> --timeout <seconds>

Example:

stress-ng --cpu 2 --timeout 60s

This command uses 2 CPU threads and runs the test for 60 seconds.

3. Run a CPU Load Test at a Specific Percentage

You can control the CPU load by specifying a percentage, which is helpful for testing different levels of CPU usage.

stress-ng --cpu-load <percentage>

Example:

stress-ng --cpu-load 50

This command keeps the CPU load at approximately 50%.


Memory Stress Testing

Stress test the system's memory by allocating and releasing blocks of memory. This can help evaluate memory stability and performance.

1. Basic Memory Stress Test

Run a memory test with a specified number of workers (processes) that continuously allocate and deallocate memory.

stress-ng --vm <workers>

Example:

stress-ng --vm 2

This command uses 2 workers to perform memory stress testing.

2. Run a Timed Memory Stress Test

Add a timeout option to run a memory test for a specific duration.

stress-ng --vm <workers> --timeout <seconds>

Example:

stress-ng --vm 2 --timeout 60s

This command uses 2 memory workers and runs the test for 60 seconds.

3. Allocate a Specific Amount of Memory

Specify the amount of memory to allocate per worker.

stress-ng --vm <workers> --vm-bytes <size>

Example:

stress-ng --vm 1 --vm-bytes 512M

This command allocates 512 MB of memory for one worker.


I/O Stress Testing

I/O testing evaluates the performance of your systems storage by reading and writing files repeatedly. This is useful for identifying storage bottlenecks and stress-testing the I/O subsystem.

1. Basic I/O Stress Test

Run an I/O test with a specified number of workers performing file operations.

stress-ng --io <workers>

Example:

stress-ng --io 4

This command runs 4 I/O workers, continuously reading and writing data to test disk performance.

2. Timed I/O Stress Test

Specify a timeout to limit the duration of the I/O stress test.

stress-ng --io <workers> --timeout <seconds>

Example:

stress-ng --io 4 --timeout 60s

This command runs the I/O stress test for 60 seconds with 4 workers.


Full System Stress Testing

For a comprehensive stress test, stress-ng allows you to stress multiple components at once, such as CPU, memory, and I/O. This puts a combined load on the system to simulate heavy usage conditions.

stress-ng --all --timeout <seconds>

Example:

stress-ng --all --timeout 10s

This command runs a 10-second full system stress test, targeting all components that stress-ng supports.