【FreeBSD】压力测试

Posted by 西维蜀黍 on 2021-03-05, Last Modified on 2021-09-21

stress

It is a simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPLv2. It is not a benchmark, but is rather a tool designed

Synopsis

$ stress [OPTION [ARG]] ...
  • -v:be verbose
  • -t N:timeout after N seconds
  • -c N:spawn N workers spinning on sqrt()
  • -i N:spawn N workers spinning on sync()
  • -m N: spawn N workers spinning on malloc()/free()
  • --vm-bytes B: malloc B bytes per vm worker (default is 256MB)
  • --vm-stride B: touch a byte every B bytes (default is 4096)
  • --vm-hang N: sleep N secs before free (default none, 0 is inf)
  • --vm-keep: redirty memory instead of freeing and reallocating
  • -d, --hdd N: spawn N workers spinning on write()/unlink()
  • --hdd-bytes B: write B bytes per hdd worker (default is 1GB)

Demo

$ pkg install stress
$ stress --cpu  8 --timeout 20

For example, a load average of four is imposed on the system by specifying two CPU-bound processes, one I/O-bound process, and one memory allocator process as follows:

$ stress -c 2 -i 1 -m 1 --vm-bytes 128M -t 10s
  • -c 2 : Spawn two workers spinning on sqrt()
  • -i 1 : Spawn one worker spinning on sync()
  • -m 1 : Spawn one worker spinning on malloc()/free()
  • –vm-bytes 128M : Malloc 128MB per vm worker (default is 256MB)
  • -t 10s : Timeout after ten seconds
  • -v : Be verbose

stress-ng

It is an updated version of stress tool and it will stress test a server for the following features:

  1. CPU compute
  2. Cache thrashing
  3. Drive stress
  4. I/O syncs
  5. VM stress
  6. Socket stressing
  7. Context switching
  8. Process creation and termination
  9. It includes over 60 different stress tests, over 50 CPU specific stress tests that exercise floating point, integer, bit manipulation and control flow, over 20 virtual memory stress tests.

Install

$ pkg install stress-ng

Demo

CPU

$ stress-ng --cpu 4 --timeout 60s --metrics-brief

Memory

Use mmap N bytes per vm worker, the default is 256MB. One can specify the size as % of total available memory or in units of Bytes, KBytes, MBytes and GBytes using the suffix b, k, m or g:

$ stress-ng --vm 2 --vm-bytes 1G --timeout 60s

The –vm 2 will start N workers (2 workers) continuously calling mmap/munmap and writing to the allocated memory. Note that this can cause systems to trip the kernel OOM killer on Linux systems if not enough physical memory and swap is not available.

Reference