Friday, October 23, 2015

Linux Benchmarking

Simple Linux Performance Script

When deploying new virtual machines with different provides I like to do basic performance tests using built in utilities like `dd` and `bc`. I had a little script linux-benchmark.sh which I have now cleaned up and making it public. When run it will do basic test for HD, Internet and CPU and save it as a timestamped text file.

Sample output:

root@sh1:~# ./linux-benchmark.sh
Please be patient, this might take a minute or so.

Hostname:             sh1
IP(s):                45.55.218.113
CPU model:            Intel(R) Xeon(R) CPU E5-2630L v2 @ 2.40GHz
Number of cores:      1
CPU frequency:        2399.998 MHz
System uptime:        60 days, 2:17,
Total amount of ram:  500 MB
Total amount of swap: 2929 MB
Calc PI to 5000:      0m31.818s
Download speed:       106MB/s
I/O (conv=fdatasync): 528MB/s
I/O (oflad=dsync):    293MB/s

The `linux-benchmark.sh` script

#!/bin/bash
# Author: Daniel Sokolowski
# source: https://bitbucket.org/snippets/danielsokolowski/G5oeA
# inspired by http://www.commandlinefu.com/commands/view/229/quick-integer-cpu-benchmark, http://serverfault.com/questions/372020/what-are-the-best-possible-ways-to-benchmark-ram-no-ecc-under-linux-arm


echo "Please be patient, this might take a minute or so."
hostname=$(cat /etc/hostname)
ips=$(hostname --all-ip-addresses)
cname=$(cat /proc/cpuinfo|grep name|head -1|awk '{ $1=$2=$3=""; print }' | xargs)  # xargs left/left trims the string
cores=$(cat /proc/cpuinfo|grep MHz|wc -l | xargs)
freq=$(cat /proc/cpuinfo|grep MHz|head -1|awk '{ print $4 }')
cpuspeed=$( (time echo "scale=5000; a(1)*4" | bc -l > /dev/null) 2>&1 | head --lines=2 | tail --lines=1 | awk -F ' ' '{print $2}')
tram=$(free -m | awk 'NR==2'|awk '{ print $2 }')
swap=$(free -m | awk 'NR==4'| awk '{ print $2 }')
up=$(uptime|awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }' | xargs) # xargs left/left trims the string

cache=$((wget -O /dev/null http://cachefly.cachefly.net/100mb.test) 2>&1 | tail -2 | head -1 | awk '{print $3 $4 }' | sed 's/^(\(.*\))$/\1/' )
io=$( (dd if=/dev/zero of=test_$$ bs=1M count=256 conv=fdatasync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')
io2=$( (dd if=/dev/zero of=test_$$ bs=1M count=256 oflag=dsync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')

# memory test
tempDir=`mktemp -d -t linux-benchmark-XXX`
mount -t tmpfs $tempDir $tempDir
#io3=$( (dd if=/dev/zero of=$tempDir/test_$$ bs=1M count=256 conv=fdatasync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')
io3=$( (dd if=/dev/zero of=$tempDir/test_$$ bs=1M conv=fdatasync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')
umount -f $tempDir
mount -t tmpfs $tempDir $tempDir
#io4=$( (dd if=/dev/zero of=$tempDir/test_$$ bs=1M count=256 oflag=dsync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')
io4=$( (dd if=/dev/zero of=$tempDir/test_$$ bs=1M oflag=dsync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')
umount -f $tempDir

outputfilename=$(basename $0-run-`date "+%Y.%m.%d-%H.%M.%S".txt`)
echo "Hostname:             $hostname" >> $outputfilename
echo "IP(s):                $ips"  >> $outputfilename
echo "CPU model:            $cname" >> $outputfilename
echo "Number of cores:      $cores" >> $outputfilename
echo "CPU frequency:        $freq MHz" >> $outputfilename
echo "System uptime:        $up" >> $outputfilename
echo "Total amount of ram:  $tram MB" >> $outputfilename
echo "Total amount of swap: $swap MB" >> $outputfilename
echo "Calc PI to 5000:      $cpuspeed"  >> $outputfilename
echo "Download speed:       $cache " >> $outputfilename
echo "HDD I/O (conv=fdatasync): $io" >> $outputfilename
echo "HDD I/O (oflad=dsync):    $io2" >> $outputfilename
echo "Memory I/O (conv=fdatasync): $io3" >> $outputfilename
echo "Memory I/O (oflad=dsync):    $io4" >> $outputfilename

echo ""
cat $outputfilename
echo ""

If you found this useful comment or follow me .

No comments:

Post a Comment