Skip to main content

bash stresstest

·5 mins
Gnu/Linux Ssh
xeylou
Author
xeylou
Table of Contents
giving some comands i like to use
to do stress tests && benchmarks

introduction
#

i wanted to share && keep at one place commands i find usefull to do stress tests && benchmarks on hosts (cpu, disk, network, ram)

i used then to test an app in over load situations

i will also explain why i found them in particular extremely usefull && what they do

i am sure some variants can be found online to fit your needs if mine are not, you can also modify them as long as i hope you understand what you do

cpu
#

for *nix hosts, a good way to check your cpu activity is by watching if its busy from your cpu load average file

its value can be found in /proc/loadavg, who is a virtual file refreshed every minute displaying you cpu load average for 1, 5 && 10 minutes

the fourth column shows the number of running processes on top of the total number of processes (in idle, zombie…)

the fifth one is the last PID created by the system

i will use this example to explain how its works

0.08 0.18 0.25 1/713 7436

the loadavg is figured out by averaging the number of jobs in the run queue (processes in R state for Running) && those waiting for disk I/O (in/out, entrée/sortie) to be processed by the CPU (in state D for Uninterruptible sleep)

so the higher the waiting processes are, the higher your cpu is busy && the higher will be your cpu load average

for example, i have a 8 thread cpu, if the loadavg is at 0.75 for the last minute, i’d have arround 6 processes waiting for cpu time or blocked (0.75*8=6)

to give a more simple example, if my loadavg was at 1, i was using on average 100% of 1 cpu thread distributed, 2 for 2 cpu threads && so on

on windows, they convert it to percentages : (your load average / your number of cpu thread) * 100, so for my example i was at 1% of my cpu at 0.08 loadavg

if my loadavg go up to 1, i would be at 12.5% of my cpu (because i have 8 cpu threads, so it’d be 12.5% of my cpu capabilities (1/8)*100)


i use a command to max out the utilization of one cpu thread, && its activity can not be distributed to other threads (because the program is coded to be single threaded)

so one thread will be at 100% of utilization && go high on temperature, the others idling at 0% at warm temperature

to do so, i use bzip2 to compress using its higher level of compression something that is in theory infinitely full to something in theory infinitely empty (it will never end)

i compress /dev/zero && prompt the output to my terminal, to redirect it into /dev/null where it’ll be deleted (nothing will be written)

in result, one cpu thread will constantly compress something (who has infinite size) to something that has no size (no disk space will be used)

the only thing your os can do is to switch the thread in utilization (from cpu thread 0 to cpu thread 4…)

bzip2 -9c /dev/zero > /dev/null

to stress out your entire cpu, you could (but shouldn’t) run this command as many times as the number of cpu threads you have

to kill all the bzip2 processes, you can do like so

kill -9 $(ps -ax | grep "bzip2" | awk '{ print $1 }')

or list them && kill one by one manually

ram
#

to overload ram, i use awk or more precisely, a specificity of the awk command

awk is a text edition tool used in commands to parse text, do maths or format output of commands when doing scripts

but what awk does is that it keep in memory the action it do

in my case, i use awk to print the first entity of the /dev/zero file - which is an infinite number of zeros, so it put in memory an infinit number of 0 until it’s full

the ram memory will soon be full after launching the command, so be carefull

awk '{print $0 ; }' /dev/zero

doing CTRL+C will stop the command from running

disk operations
#

to saturate disk iops, i simply use cat to read at full speed the content of a disk, && i redirect it to write to saturate write

for this command i assume you are in root

you can simply show the content of your disk, because everything is a file in linux, your entire disk can be read from /dev/sda for example; && i redirect the output to /dev/null (the void)

cat /dev/sda /dev/null

to stress the write of a disk, i need to truly create a file that will increase its size

to do so, i cat a file infinitly full to a new file that will grow bigger && bigger

cat /dev/zero > ~/tmp_gigantic_file

while doing so, you can do your test manipulation to try the scenario of a overloaded disk

network
#

to overload the network (tx && rx), i need an other machine to do so

what i do is the same for the disk operations, but over the network : i read /dev/zero localy && send the output to the /dev/null of the other machine (for tx)

dd if=/dev/zero | ssh <your_host> dd of=/dev/null

&& for rx, i simply do the same the other way around (asking the remote machine to send to me)

ssh <your_host> dd if=/dev/zero | dd of=/dev/null