Skip to main content

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 .

Comments

Popular posts from this blog

Opera SOCKS Proxy Setup Issues

SOCKS error: Connection closed by remote server When setting up SOCKS only proxy in Opera web browser make sure to specify the IP address instead of your fully qualified domain name (FQDN). Using a host name will not work and Opera simply fails to connect to the proxy server. Sample working setup screen shot with a Dante proxy server , note that HTTP, HTTPS, FTP, SSH options are left blank. Bug DSK-364301 has been filled with Opera, if it has been a while since this post and the issue still not fixed feel free to add your word of encouragement by emailing DSK-364301@bugs.opera.com :)

Storing passwords in PuTTY

How to save SSH username/password for auto login in PuTTy The answer is you can't do it...at least in plain PuTTy. However there is an awesome fork with that let's you store the username and password and other additional features called KiTTy.



So grab yourself a copy and +1 this if you do, thanks.

How to child proof a fireplace

DIY - Do it yourself fireplace child guard Our wonderful 8.5 month old Sofia has become a crawling race car with an untamed thirst for exploration. And so with the cold nights approaching we needed to child proof the fireplace. This however proved to be more difficult than would reasonably expect, I've checked the local Toys "R" Us, Walmart, and even a Canadian Tire with no success for a ready to use product. Internet search was more fruitful and returned a few online stores one could order from, however in all honestly they didn't look too sturdy to me. So I build my own relatively quickly and inexpensively. Materials needed is a privacy plastic lattice - the smallest hole pattern - a few screws and anchors; tools needed are a drill, and a handsaw if you don't have the lattice cut at the store - that’s it. The construction consits of screwing the lattice into the wall and the final product is easiest explained through following pictures. Feel free to +1 this po…