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

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…

Duplicate value found: duplicates value on record with id: <unknown>.

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>.The above error is triggered in the database layer and caused by a trigger or workflow outside of your main code of block that is bubbling this exception. This is rather difficult to track down especially if you are unfamiliar with the code, I am sharing my procedure in the hopes this saves you time - if you find this helpful drop me a line or follow me on twitter @danielsokolows. This error is caused by unique field constraint on the object, so the first step is to examine the object and locate the API names of all unique fieds. You can do this through SF direclty 'Setup < Customize &lt <object being inserted> &lt Fields' or by downloading the `src/objects` metadata information and searching for <unique>; I preffer the latter and actually download ALL matadata information f…

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.