Thursday 26 March 2020

Using ‘dd’ to benchmark disk 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 fiobonnie++ 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
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 ~]#
Source