Thursday, 14 March 2013

Linux Stress tests

Consume CPU:

Fork bomb:

:(){ :|:& };:
The next one will load four CPU cores at 100%:
for i in `seq 1 4` ; do while : ; do : ; done & ; done
Or:
for i in `seq 1 4` ; do cat /dev/zero > /dev/null & ; done
Or:
#!/bin/bash
duration=120 # seconds
instances=4 # cpus
endtime=$(($(date +%s) + $duration))
for ((i=0; i<instances; i++))
do
while (($(date +%s) < $endtime)); do : ; done &
done
Using the stress tool:
stress --cpu 3

Consume RAM:

Create a 30gb ramdisk and fills it with file full of zeroes:
sudo mount -t tmpfs -o size=30G tmpfs /mnt
dd if=/dev/zero of=/mnt/tmp bs=10240 count=30720MB

Create a giant virable:
x="x" ; while : ; do x=$x$x ; echo -n "." ; done

Consume Disk:

dd if=/dev/zero of=bigfile bs=10240 count=30720MB

Simulate packet loss:

For randomly dropping 10% of incoming packets:
iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP
and for dropping 10% of outgoing packets:
iptables -A OUTPUT -m statistic --mode random --probability 0.1 -j DROP


Possibly Related Posts

No comments:

Post a Comment