Ir al contenido

Comandos de stress-ng

stress-ng es una herramienta completa de pruebas de estrés que ejercita varios subsistemas físicos de un ordenador e interfaces del kernel del sistema operativo. Soporta más de 300 estresores para CPU, memoria, sistema de archivos, red y más, con métricas incorporadas y soporte de archivos de trabajo YAML.

Instalación

Linux/Ubuntu

# Ubuntu/Debian
sudo apt install stress-ng

# Fedora/RHEL
sudo dnf install stress-ng

# Arch Linux
sudo pacman -S stress-ng

# From source
git clone https://github.com/ColinIanKing/stress-ng.git
cd stress-ng && make && sudo make install

# Verify installation
stress-ng --version

Estresores de CPU

# Stress all CPUs with default method for 60 seconds
stress-ng --cpu 0 --timeout 60s

# Stress a specific number of CPU workers
stress-ng --cpu 4 --timeout 60s

# Use a specific CPU stressor method
stress-ng --cpu 4 --cpu-method matrixprod --timeout 60s

# List available CPU methods
stress-ng --cpu-method which

# Common CPU methods:
# matrixprod — matrix multiplication
# fft — Fast Fourier Transform
# ackermann — Ackermann function (recursive)
# bitops — bitwise operations
# callfunc — function call overhead
# double — double precision floating point
# euler — Euler's number calculation
# fibonacci — Fibonacci sequence
# int64 — 64-bit integer ops
# prime — prime number search

# Stress with specific CPU load percentage
stress-ng --cpu 4 --cpu-load 75 --timeout 60s

# Pin stressors to specific CPUs (taskset style)
stress-ng --cpu 2 --taskset 0,1 --timeout 60s

# Stress and show metrics
stress-ng --cpu 4 --cpu-method matrixprod --timeout 60s --metrics-brief

Estresores de memoria

# Stress memory (malloc/free cycles)
stress-ng --vm 2 --vm-bytes 1G --timeout 60s

# Memory stress with specific pattern checking
stress-ng --vm 2 --vm-bytes 512M --vm-method all --timeout 60s

# Keep memory allocated (don't free)
stress-ng --vm 2 --vm-bytes 1G --vm-keep --timeout 60s

# Memory stress with mmap
stress-ng --mmap 2 --mmap-bytes 1G --timeout 60s

# Stack stress
stress-ng --stack 4 --timeout 60s

# Brk stress (heap expansion)
stress-ng --brk 2 --timeout 60s

# Malloc stress (rapid allocation/deallocation)
stress-ng --malloc 4 --malloc-bytes 64K --timeout 60s

# Memory bandwidth measurement
stress-ng --memrate 1 --timeout 30s --metrics-brief

# Big heap allocation stress
stress-ng --bigheap 2 --timeout 60s

# Zero memory pages stress
stress-ng --zero 2 --timeout 30s

# Out-of-memory stress (careful — can trigger OOM killer)
# stress-ng --oom-pipe 1 --timeout 30s

Estresores de E/S de disco

# Sequential I/O stress
stress-ng --hdd 4 --timeout 60s

# Specific I/O size
stress-ng --hdd 4 --hdd-bytes 2G --timeout 60s

# Random I/O stress
stress-ng --seek 4 --timeout 60s

# Sync I/O (fsync after each write)
stress-ng --hdd 4 --hdd-opts sync --timeout 60s

# AIO (async I/O) stress
stress-ng --aio 4 --timeout 60s

# IO-uring stress (Linux 5.1+)
stress-ng --io-uring 4 --timeout 60s

# Filesystem metadata stress (create/delete files)
stress-ng --dentry 4 --timeout 60s

# Directory operations stress
stress-ng --dir 4 --timeout 60s

# File locking stress
stress-ng --flock 4 --timeout 60s

# Write to a specific temp directory
stress-ng --hdd 4 --temp-path /mnt/fast-disk --timeout 60s

# Mixed read/write workload
stress-ng --hdd 2 --hdd-opts rd-rnd,wr-seq --timeout 60s

Estresores de red

# TCP socket stress
stress-ng --sock 4 --timeout 60s

# UDP socket stress
stress-ng --udp 4 --timeout 60s

# Unix domain socket stress
stress-ng --sockpair 4 --timeout 60s

# SCTP socket stress
stress-ng --sctp 4 --timeout 60s

# Network device stress (loopback)
stress-ng --netdev 2 --timeout 60s

# Socket file descriptor stress
stress-ng --sockfd 4 --timeout 60s

Estresores de VM y kernel

# Fork stress (process creation)
stress-ng --fork 4 --timeout 60s

# Vfork stress
stress-ng --vfork 4 --timeout 60s

# Context switch stress
stress-ng --switch 4 --timeout 60s

# Pipe stress
stress-ng --pipe 4 --timeout 60s

# Signal handling stress
stress-ng --signal 4 --timeout 60s

# Timer stress
stress-ng --timer 4 --timeout 60s

# Futex stress (lock contention)
stress-ng --futex 4 --timeout 60s

# Semaphore stress
stress-ng --sem 4 --timeout 60s

# Scheduler stress
stress-ng --sched 4 --timeout 60s

# Clone/unshare stress (namespace creation)
stress-ng --clone 4 --timeout 60s

# Cgroup stress
sudo stress-ng --cgroup 4 --timeout 60s

Métricas y estadísticas

# Show brief metrics summary
stress-ng --cpu 4 --timeout 60s --metrics-brief

# Show detailed metrics
stress-ng --cpu 4 --timeout 60s --metrics

# Include thermal zone info
stress-ng --cpu 4 --timeout 60s --metrics --tz

# Log output to a file
stress-ng --cpu 4 --timeout 60s --metrics --log-file stress.log

# Show per-stressor timing
stress-ng --cpu 4 --vm 2 --timeout 60s --times

# Output results in YAML format
stress-ng --cpu 4 --timeout 60s --metrics-brief --yaml stress-results.yaml

# Output in JSON format
stress-ng --cpu 4 --timeout 60s --metrics-brief --json stress-results.json

# Verbose output
stress-ng --cpu 4 --timeout 60s -v

Archivos de trabajo YAML

# Save as stress-job.yaml
# Run with: stress-ng --yaml stress-job.yaml

# stress-job.yaml
# A mixed stress test job
---
global:
  timeout: 120s
  metrics-brief: true

stressors:
- cpu:
    instances: 4
    cpu-method: matrixprod
- vm:
    instances: 2
    vm-bytes: 512M
- hdd:
    instances: 2
    hdd-bytes: 1G
- sock:
    instances: 2
# Run a YAML job file
stress-ng --job stress-job.yaml

# Override timeout from job file
stress-ng --job stress-job.yaml --timeout 300s

Pruebas térmicas y de energía

# CPU stress with thermal monitoring
stress-ng --cpu 0 --timeout 300s --metrics --tz

# Monitor thermal zones during test
stress-ng --cpu 0 --timeout 120s --tz &
watch -n 1 'cat /sys/class/thermal/thermal_zone*/temp'

# Sustained load for thermal throttling tests
stress-ng --cpu 0 --cpu-method matrixprod --timeout 600s --metrics-brief --tz

# Low-power stress (minimal CPU load)
stress-ng --cpu 1 --cpu-load 10 --timeout 300s

Estresores basados en clases

# Stress all CPU-bound stressors
stress-ng --class cpu --sequential 1 --timeout 10s --metrics-brief

# Stress all memory stressors
stress-ng --class memory --sequential 1 --timeout 10s --metrics-brief

# Stress all I/O stressors
stress-ng --class io --sequential 1 --timeout 10s --metrics-brief

# Stress all network stressors
stress-ng --class network --sequential 1 --timeout 10s --metrics-brief

# Stress all OS/kernel stressors
stress-ng --class os --sequential 1 --timeout 10s --metrics-brief

# List available stressor classes
stress-ng --class which

# Run all stressors sequentially (comprehensive system test)
stress-ng --sequential 1 --timeout 5s --metrics-brief

# Run random stressors
stress-ng --random 8 --timeout 60s --metrics-brief

Cargas de trabajo combinadas

# Simulate a web server workload
stress-ng --cpu 4 --vm 2 --vm-bytes 256M --sock 4 --fork 2 --timeout 120s --metrics-brief

# Simulate a database workload
stress-ng --cpu 2 --hdd 4 --hdd-bytes 4G --vm 2 --vm-bytes 1G \
          --seek 4 --flock 2 --timeout 120s --metrics-brief

# Simulate a CI/CD build workload
stress-ng --cpu 0 --fork 8 --hdd 2 --pipe 4 --timeout 180s --metrics-brief

# Memory pressure test (gradually increase)
stress-ng --vm 1 --vm-bytes 25% --timeout 60s --metrics-brief
stress-ng --vm 1 --vm-bytes 50% --timeout 60s --metrics-brief
stress-ng --vm 1 --vm-bytes 75% --timeout 60s --metrics-brief

# Quick system stability check (2 minutes)
stress-ng --cpu 0 --vm 2 --vm-bytes 1G --hdd 2 --fork 4 --timeout 120s --metrics-brief

Referencia rápida

OpciónPropósito
--cpu NN CPU worker processes (0 = all cores)
--vm NN virtual memory workers
--vm-bytes SIZEMemory per VM worker
--hdd NN disk I/O workers
--hdd-bytes SIZEData per HDD worker
--sock NN socket workers
--timeout DURATIONTest duration (e.g., 60s, 5m, 1h)
--metrics-briefShow performance metrics summary
--tzMonitor thermal zones
--class NAMERun all stressors of a class
--sequential NRun stressors one at a time
--random NRun N random stressors
--job FILERun from YAML job file
--cpu-load PCTTarget CPU utilization percentage
--yaml FILEOutput results in YAML
--json FILEOutput results in JSON