IBM Support

Stress test your AIX or Linux server with nstress

How To


Summary

The stress package is a set of programs to keep many parts of the computer busy including CPU, memory, file systems, inter-process communications, and disks.

Objective

Nigels Banner

Possible uses of the programs in the nstress toolbox are:

  • You can "burn in" new hardware to prove it is reliable before production use

  • You can find out how fast your computer runs like memory speeds or disk I/O

  • You can generate "fake" workloads and then use performance monitoring tools like nmon or njmon to see the performance stats in action.

Environment

If you over do the generated workload, then make sure that there is no other users on your computer (or VM) because nstress can grind your computer to a stop.
man sweating over his computer
The author focuses on POWER processor-based computers but these tools are additionally compiled for AMD64 (x86_64)

Steps

There are a number of uses:

  • Soak testing = check a new machine/disk to remove early life failures
  • Prove performance of machine upgrades or alternative disk configurations
  • Learn performance monitoring and tuning
  • For example, I run a Performance Tuning Expert Class. The class needed to quickly set-up many different workloads and problems to be investigated and solved by students. 

 The programs are: 

Name Purpose
ncpu Hammers the CPUs (can be slowed down to use a percentage)
ndisk Removed - use ndisk64
ndisk64 Hammers the disks compiled for large files so it can access large files (many GBs)
ndiskaio Removed - use ndisk64
ndiskmio Removed. Uses the Modular IO AIX Expansion pack library must be installed (experimental not currently available)
nmem Hammers or touches memory
nmem64 Hammers or touches memory - complied 64 bit so it has access large memory (many GBs)
nipc Tests shared memory, semaphores, and shared messages in a ring of processes - takes 1 CPU
nlog Generates output like error messages. You specify the data size in kilobytes (KB) output per second
nfile Creates, writes, and deletes files to push the JFS and JFS log hard
createfs.sh Example script to create the file systems. Edit the file to match your system.
dbstart.sh Example script to start a fake database RDBMS. Edit the file to match your system.
webstart.sh Example script to start a fake web server. Edit the file to match your system.

Download the pre-compiled programs:

  • These files contains all the binary command files and scripts.
  • AIX tar files:
  • Linux (Little Endian) on Power tar files for computers that use the POWER processor:
    • These files moved to https://github.com/nigelargriffiths/nstress
    • Note: ndisk64 had to be radically hacked about and features disabled to get it to compile so I would consider this different source code - don't expect all the options in the AIX version to be available. Help information might be a bit wrong!
    • Big Endian Linux support was dropped in the days of POWER7.
  • Linux on AMD (x86_64)
    • These files moved to https://github.com/nigelargriffiths/nstress
    • If your Linux distribution and release are not found here, try one of the other Linux files.
      • If the tool starts without and error, then the C library (libc) is close enough and runs fine. 
  • Warnings:
    • Do not consider these tools as benchmark programs - they are hardware and operating system stress tools.
    • Do not compare AIX with Linux - it is different code and different compilers. Especially ndisk64.
    • Do not compare Linux ppc64 and Linux x86_64 - I did not install the Advanced Tool Chain on ppc64 to get the optimized compiler, which would give up to 35% better performance.
    • Do not compare Linux with Linux - due to the different ages of the OS, different kernel levels, different libraries (libc), and different GCC versions. It is NOT a fair comparison. 
    • Special ndisk64 version 75 notes:
      • Always use the -M procs option to specify the number of processes to use or it hangs.
      • Recommended: using the -s size option to specify the file size
      • The Async I/O is completely missing in the code.  Don't believe the help information (ndisk -?).
      • The command-line option -C for CIO and -D for DIO are not available. 
        Use Direct I/O by using the /dev/rsda9 type volume but make sure it is NOT a file system or it trashes your files in a nanosecond.
  • Note: When ncpu is run by the root user, it tries to boost its processor priority.
    • This CPU priority boost effectively locks out an entire CPU. A good option to have in your toolbox.  This tool effectively removes the CPU from your configuration. Note: Since 2010, PowerVM dynamic LPAR changes (DLPAR) are a safer way to change the number of CPUs.  Other hypervisors like VirtualBox and VMware can allow such changes.

Warranty = NONE

  • It is strictly at your own risk.
  • It is possible to hang the entire server.
    • Use the option that stops the tool in a few minutes, otherwise halt your operating system to stop the nstress tool.
    • As an example the command-line option "-s 300" Note: 300 seconds is five minutes.
  • If you run these programs as a regular user, then no harm can be to your system.
  • If you run these programs as the root user, they can be dangerous and even hang the machine due to total saturation of CPU or memory or disk I/O.
The C Source Code is not available to the public currently (December 2023).
  • When released, find it on GitHub.
  • A C compiler and make command are needed to compile all the tools in a few seconds.

Additional Information

Note: Most commands now have the following options

Rename yourself option: -o

  • This option allows the process to rename itself so that it looks like something else when it is running.
  • For example, a database. * This HAS to be the LAST option on the line.
  • These tools fool the ps and nmon programs.
  • I call the masquerading.

Snooze mode: -z

  • This option causes the program to not run flat out and so behave like a user-driven command.
  • This snoozing is performed at the millisecond level and is quickly effective.

Second to run and then stop: -s

  • This option specifies the maximum time in seconds to run.
  • ALWAYS use this option to make sure the programs stop, otherwise you can slow down a machine forever (or reboot). If you "over-cook" the workload by starting too many programs, the machine can stop responding. This option is better than reboot the server or virtual machine.

Manual pages = the help output of the programs

ncpu -h output
Usage: ncpu version 9.0 hammers the cpu(s)
Note: root users get a priority boost = effectively removes the CPU(s)

Hint hammer CPU mode: ncpu -p procs [-z percent] [-s secs] [-h secs] [-o "cmd"]
        -p procs   = number of copies of cpu to start (max=256)
        -z percent = Snooze percent - time spent sleeping (default 0)
        -s seconds = Seconds maximum run time (default no limit)
        -h seconds = Seconds to sleep after each second of run time
        -o "cmd" = Other command - pretend to be this other cmd when running
                Must be the last option on the line

Hints

Run in CPU counter mode:  

ncpu -c
Run on eight CPUs but not use the last 20% of the CPUS, stop after 15 minutes and add jitter and the ps command reports the processes as DB2
ncpu -p 8 -z 20 -s 900 -h1 -o DB2inst

ndisk64 Help Output

ndisk64 version 7.4
Complex Disk tests - sequential or random read and write mixture
ndisk64 -S          Sequential Disk I/O test (file or raw device)
        -R          Random    Disk I/O test (file or raw device)

        -t <secs>   Timed duration of the test in seconds (default 5)

        -f <file>   use "File" for disk I/O (can be a file or raw device)
        -f <list>   list of filenames to use (max 16) [separators :,+]
                        example: -f f1,f2,f3  or -f /dev/rlv1:/dev/rlv2
        -F <file>   <file> contains list of filenames, one per line (upto 2047 files)
        -M <num>    Multiple processes used to generate I/O
        -s <size>   file Size, use with K, M or G (mandatory for raw device)
                        examples: -s 1024K   or   -s 256M   or   -s 4G
                        The default is 32MB
        -r <read%> Read percent min=0,max=100 (default 80 =80%read+20%write)
                        example -r 50 (-r 0 = write only, -r 100 = read only)
        -b <size>   Block size, use with K, M or G (default 4KB)
        -O <size>   first byte offset use with K, M or G (times by proc#)
        -b <list>   or use a colon separated list of block sizes (31 max sizes)
                        example -b 512:1k:2K:8k:1M:2m
        -q          flush file to disk after each write (fsync())
        -Q          flush file to disk via open() O_SYNC flag
        -i <MB>     Use shared memory for I/O MB is the size(max=256 MB)
        -v          Verbose mode = gives extra stats but slower
        -l          Logging disk I/O mode = see *.log but slower still
        -o "cmd"  Other command - pretend to be this other cmd when running
                        Must be the last option on the line
        -K num      Shared memory key (default 0xdeadbeef) allows multiple programs
                    Note: if you kill ndisk,  you may have a shared memory
                    segment left over. Use ipcs and then ipcrm to remove it.
        -p          Pure = each Sequential thread does read or write not both
        -P file     Pure with separate file for writers
        -C          Open files in Concurrent I/O mode O_CIO
        -D          Open files in Direct I/O mode O_DIRECT
        -z percent  Snooze percent - time spent sleeping (default 0)
To make a file use dd, for 8 GB: dd if=/dev/zero of=myfile bs=1M count=8196

Asynchronous I/O tests (AIO) This now uses POSIX threads and  Async I/O API
        -A         switch on Async I/O use: -S/-R, -f/-F and -r, -M, -s, -b, -C, -D to determine I/O types
                (JFS file or raw device)
        -x <min>   minimum outstanding Async I/Os (default=1, min=1 and min<max)
        -X <max>   maximum outstanding Async I/Os (default=8, max=1024)
        see above -f <file>  -s <size>   -R <read%>  -b <size>
For example:
        dd if=/dev/zero of=bigfile bs=1m count=1024
        ndisk64 -f bigfile -S -r100 -b 4096:8k:64k:1m -t 600
        ndisk64 -f bigfile -R -r75 -b 4096:8k:64k:1m -q
        ndisk64 -F filelist -R -r75 -b 4096:8k:64k:1m -M 16
        ndisk64 -F filelist -R -r75 -b 4096:8k:64k:1m -M 16 -l -v
For example:
        ndisk64 for Asynch compiled in version
        ndisk64 -A -F filelist -R -r50 -b 4096:8k:64k:1m -M 16 -x 8 -X 64


nmem64 Help Output

$ ./nmem64
Usage: nmem version 6.1
Hint: nstress tool to hammer memory (do not use this on production machines)
 use 1: mallocs memory and then touches the memory pages at random
 use 2: cycles though memory speed test to determine/guess cache sizes (-c option)
 output includes memory size used, operations performed, time taken and ops per second

        nmem -m Mbytes [-s MaxSeconds] [-z percent][-o "cmd"]
                Mbytes     = Size of RAM to use in mega-bytes
                             For nmem the max is 255 (~256MB) and for nmem64 the max is 2047 (~2GB))
                MaxSeconds = maximum time of the test.
                        Use this to halt nmem even if you drove your OS to a stand still.
                        You have been warned!
                percent    = Snooze percent - nmem sleeps for the percentage of the time
                cmd        = nmem with pretend to be a process called cmd.
                             This option must be the last on the line in double quotes


        Memory speed test with increasing memory sizes
        - may highlight CPU cache sizes

        nmem -c [-s MaxSeconds]

                MaxSeconds = maximum time of the test (default 60)
Example:
        nmem -m 250 -s 300               - grab and randomly touch 256 MB of memory for 5 minutes
        nmem -m 250 -s 300 -z 80         - as above but slower, sleep 80% of the time
        nmem -c -s 600                   - cycle through tests (maximum of 10 minutes)
        nmem -m 6 -o "sally -x"          - Use 6 MB pretend to be process sally with parameter -x

If your OS complains about the size of memory use you hit your ulimit
         For 256MB+ try: ulimit -d unlimited


nlog Help Output

./nlog -h
Usage: nlog version 3.0
Hint: generates a log file at a steady rate to standard error
        nlog -k Kbytes -s Seconds -m MaxSeconds -o "cmd"
        nlog -k 1 -s 60                 is the default
Example:
        nlog -k 2 -s 1 -m 600            - 2 K per second for 10 minutes
        nlog -k 2 -s 1                   - 2 K per second forever
        nlog -k 2 -s 1 -o "bert -x"      - 2 K per second pretend to be process bert with parameter -x
        nlog -k 1 -s 60 -m 300           - 1 K per minute for 5 minutes
        nlog -k 200 -s 1 -m 3600         - 200 K per second for an hour


nipc Help Output

This tool runs processes that communicate with shared memory with control that use Class and need to a UNIX IPC semaphore and then back again with a message queue.

Usage: nipc version 2.0
nipc: hammers inter-process communication (IPC) 
    that is shared memory, semaphores and message queues

hint: nipc -p procs -s seconds

nfile Help Output

Usage: nfile version 2.0
Hint: creates and deletes files = generates JFS log file work
nfile -d directory [-k Kbytes] [-c Files] [-m MaxSeconds] [-z percent] [-o "cmd"]
        -d directory  - top level directory
        -k Kbytes     - size of the files to create in KB (default 4KB)
        -c Files      - number of files to maintain (+/- 10) (default 4096)
        -m MaxSeconds - stop of so many seconds
        -z percent    - percent of time to sleep/snooze
        -o "cmd"    - pretend to be a different cmd (must be the last option)
Example:
        nfile -d mydir -k 1 -c 10000 -m 600
        nfile -d /tmp/files -k 64 -o "bert -x"

Other places to find content from Nigel Griffiths IBM (retired)

Document Location

Worldwide

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"Component":"","Platform":[{"code":"PF002","label":"AIX"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"HW1W1","label":"Power -\u003EPowerLinux"},"Component":"","Platform":[{"code":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"","label":""}}]

Document Information

Modified date:
30 December 2023

UID

ibm11111065