June 17th 2019: Added instructions for network speed test using speedtest-cli script.

Oct 31st 2017: Also see this list of command line scripts.

Nov 2nd 2016: Included quick dd commands to check cached vs uncached disk read performance.



This article will highlight using the ‘dd’ Unix command for a quick benchmark of your Linux server or VPS. ‘dd’ requires no downloads and can quickly alert you to any performance bottlenecks and/or indicate if there’s need for additional benchmarks using more complex tools.

Are you hosted on a Cloud, VPS or Dedicated server and struggle with performance issues? When raising these issues to your web host, do they always seems to simply blame everything on your so-called “heavy” website? If you are tired of being hung out to dry, lets do something about it. To get started, lets try to identify or eliminate your web host/server from the bad-performance equation using ‘dd’ commands to benchmark your disk, memory and CPU performance.

The screenshot below shows a few of the dd commands being run on a tiny but under load (6GB RAM) StackLinux VPS. If you’re interested in super fast SSD based VPS hosting you can request an invite here.

Now, lets look into the ‘dd’ command we will be using. ‘dd’ is a command on Unix and Unix-like operating systems (such as Linux) whose primary purpose is to convert and copy a file. We will use ‘dd’ to create a file named ‘diskbench’ with all zeroes in it. We will also instruct ‘dd’ to sync this to disk and to ensure that writes do not remain in memory (RAM) which would not give accurate results of the write speed if memory buffer is used (we will leave that for a later test).

Using ‘dd’ to benchmark disk write performance

To get started you should change to a directory to which you have read and write permissions. Or create and enter a new directory:

mkdir /home/bench/ cd /home/bench/

Make sure you have a few gigabytes of free disk space. Then use the following command to test the write speed of your storage:

dd if=/dev/zero of=diskbench bs=1M count=1024 conv=fdatasync

The results looks something like this from Stacklinux’s 3GB VPS:

1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 0.553284 s, 1.9 GB/s

You’ll want this to be above 400 MB/s.

Using ‘dd’ to benchmark storage read performance

Now, lets delete the server’s buffer cache in order to measure ‘read’ speeds direct from the hard drive:

echo 3 | sudo tee /proc/sys/vm/drop_caches

Now that cache is deleted, we can test disk read performance of that ‘diskbench’ file using:

dd if=diskbench of=/dev/null bs=1M count=1024

This outputs the following:

1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 0.425812 s, 2.5 GB/s

Using ‘dd’ to benchmark memory-buffered read performance

After running the above command, the data will be pushed to memory-buffered cache. So lets test read speeds using memory buffer by repeating the previous command:

dd if=diskbench of=/dev/null bs=1M count=1024

Which outputs the following:

1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 0.135034 s, 8.0 GB/s

You should run this test a couple of times to a find the average. Lastly, remember to delete the 1.1GB test file using this command:

rm diskbench

If your results point to poor read/write performance you may want to look into upgrading hardware or switching your web hosts. In addition, more extensive tests can be performed using fio, bonnie++ or IOzone.

Using ‘dd’ to benchmark CPU performance

If you would like to verify CPU speed and # of cores. Use the following commands:

lscpu

‘lscpu’ gathers CPU architecture information from sysfs and /proc/cpuinfo. The information includes the number of CPUs, threads, cores etc. There is also information about the CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping.

nproc

‘nproc’ prints the number of processing units (cpu cores) available.

Now ‘dd’ can also be used for a simple CPU benchmark using:

dd if=/dev/zero bs=1M count=1024 | md5sum

The results:

1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 2.5454 s, 422 MB/s cd573cfaace07e7949bc0c46028904ff -

For most modern CPUs, you’ll want to see a minimum of 300 MB/s. Lower than that should prompt you to perform more accurate tests using BYTEmark or even unixbench. To sum things up, no matter your experience level, ‘dd’ can be used as a quick check into the disk, memory and CPU performance of your web server.

Using speedtest-cli for testing internet bandwidth

speedtest-cli is a command line interface for testing internet bandwidth using speedtest.net. Issue the following commands to download and run the network speed test script:

wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py chmod +x speedtest-cli

or

curl -Lo speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py chmod +x speedtest-cli

./speedtest-cli

or for usage/help use:

./speedtest-cli -h

For reference, here’s a cut-an-paste of results as tested on an 8GB DigitalOcean droplet:

[root@droplet ~]# dd if=/dev/zero of=diskbench bs=1M count=1024 conv=fdatasync 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 2.51205 s, 427 MB/s [root@droplet ~]# dd if=/dev/zero of=diskbench bs=1M count=1024 conv=fdatasync 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 2.84208 s, 378 MB/s [root@droplet ~]# dd if=/dev/zero of=diskbench bs=1M count=1024 conv=fdatasync 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 2.09716 s, 512 MB/s [root@droplet ~]# echo 3 | sudo tee /proc/sys/vm/drop_caches 3 [root@droplet ~]# dd if=diskbench of=/dev/null bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 1.55411 s, 691 MB/s [root@droplet ~]# dd if=diskbench of=/dev/null bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 0.348052 s, 3.1 GB/s [root@droplet ~]# dd if=diskbench of=/dev/null bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 0.202393 s, 5.3 GB/s [root@droplet ~]# rm diskbench rm: remove regular file `diskbench'? y [root@droplet ~]# nproc 4 [root@droplet ~]# dd if=/dev/zero bs=1M count=1024 | md5sum 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 3.34115 s, 321 MB/s cd573cfaace07e7949bc0c46028904ff - [root@droplet ~]# dd if=/dev/zero bs=1M count=1024 | md5sum 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 3.17004 s, 339 MB/s cd573cfaace07e7949bc0c46028904ff - [root@droplet ~]# dd if=/dev/zero bs=1M count=1024 | md5sum 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 3.09961 s, 346 MB/s cd573cfaace07e7949bc0c46028904ff - [root@droplet ~]#