Best Linux Tools To Benchmark Your Server

Introduction

Best Linux Tools To Benchmark Your Server
Best Linux Tools To Benchmark Your Server

We will go over Best Linux Tools To Benchmark Your Server.

Did you know that linux offers a few good tools to benchmark your server entirely from the command line?

We will break down this in the following sections:

  • How To Benchmark Your Network Speed In Linux
  • How To Benchmark Your Disk Speed In Linux
  • How To Find Your Memory In Linux
  • How To Check Your CPU Speed In Linux

I have used these commands successfully in various projects and they work very well and have saved me a ton of time getting a quick assessment if a server is good or not.

We will go point by point on getting you up and running in less than 5mins, you do not need to have any programming knowledge to use the tools we are going to be using here.

This is a complete guide and should cover all your questions on working understanding how to benchmark a Linux server.

We will start by benchmarking our network speed. A lot of you already know that when selecting a server or wanting to evaluate the network link that you are in to measure things such as:

  • Latency
  • Upload speed
  • Download speed

You need a quick and easy tool to do this. My preference over the years and goto solution has been speedtest. It offers a quick and easy way to do this without setting up servers and clients just using public hosts.

If you want to measure a connection link between two machines then you will need a more specialized tool link iperf3. Since this article is to benchmark in general your network speed to the outside world and nothing in specific we will be using speedtest here and skipping the iperf3 tool. If you however would like to learn more about it please send me a note below and I’ll be adding this section too.

So the first step you need to do is go ahead and install it in your system. I’m using a Debian based system like Ubuntu so all the commands below will be based on that but similarly in other distributions you should be able to find the installation package.

Ubuntu offers speedtest cli out of the box so simply issue the below command to get it installed in your system.

$ sudo apt install speedtest-cli
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
speedtest-cli is already the newest version (2.1.3-2).

Now that we have successfully installed speedtest we can go ahead and start running a test to the outside world and seeing how it performs.

$ speedtest
Retrieving speedtest.net configuration...
Testing from RamNode LLC (XXXXX)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Kansas Research and Education Network (Wichita, KS) [43.14 km]: 42.455 ms
Testing download speed................................................................................
Download: 345.56 Mbit/s
Testing upload speed......................................................................................................
Upload: 433.43 Mbit/s

In our case we are testing a cheap VPS running at ramnode so speedtest has picked a server near it to test it out. You can see the following important information on the test above:

  • Latency: 42ms, this means a single packet between our server and the closes Kansas research server we are testing with takes 42ms to initiate transfer.
  • Download: The downstream above is 345mbits this is pretty much self explanatory
  • Upload: Same as above the speed is 433mbits

The above tool quickly allowed us to evaluate network speed in a random server online that was near ramnode, but what if we want to test a more distant server? No problem if you run speedtest there’s an option to list all the servers it has detected for this particular test. To do this you can run the command below:

$ speedtest --list
Retrieving speedtest.net configuration...
33629) SBA Edge (West Chicago, IL, United States) [21.81 km]
47744) AT&T (Cicero, IL, United States) [26.69 km]
10135) CenturyLink (Chicago, IL, United States) [31.77 km]
28363) Xiber LLC (Chicago, IL, United States) [31.77 km]
 5919) tzulo, inc (Chicago, IL, United States) [31.77 km]
37497) Netprotect (Chicago, IL, United States) [31.77 km]
 2574) ServerCentral (Chicago, IL, United States) [31.77 km]
46119) GSL Networks (Chicago, IL, United States) [31.77 km]
47532) Urban Communications (Oak Forest, IL, United States) [49.32 km]
14162) University of Notre Dame (Notre Dame, IN, United States) [149.45 km]

So now having the information above we can run it against a particular server. To do this we need to adjust the command line to the following syntax:

$ speedtest --server 28363

Specifying a server allows us to do a random test on another server to see how we are performing. Repeating this process in multiple servers will allow us to get a median value and see how well we do.

Similar to speedtest another honorable mention for a tool is fast cli this is a service provided exclusively from Netflix. In order to install this its a bit more tricky and you will need npm installed in your system. If you do not have npm installed you can pull the instructions from here to get it running.

Once you have npm installed you can simply pull in the dependencies and install it using the command as shown below.

$ sudo npm install --global fast-cli

added 230 packages, and audited 231 packages in 6s

35 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

It accomplishes the same result as above but works with their own servers and has less options on how to its. The simplest syntax is the one listed below which lets you run a basic download test.

$ fast
  â § 450 mbit

This same thing can be accomplished if you simply went to the webpage of fast.com to see the result. The output will be similar to this.

How To Benchmark Network Speed In Linux
How To Benchmark Network Speed In Linux

The above was executed from my desktop for simplicity but you get the idea the result is basically the same as if you were to run it from the command line terminal of the Linux server you are trying to benchmark.

Moving on we will be covering how to benchmark your disk speed in Linux. The process of doing this is fairly simple thanks to a great package called hdparm. That Linux utility allows you to test your disk speed for read and write access.

To get it installed simply invoke the command below using the apt command. Again this works in a Debian based Linux distribution but other distributions support this package by default since it’s so popular.

$ sudo apt install hdparm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
hdparm is already the newest version (9.60+ds-1build3).
hdparm set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.

Now that we have hdparm installed let’s proceed and tell it to do two tests for us:

  • Cached reads from the drive, this is data that was recently read and we need to re-read it
  • Normal buffered reads, this is new data that we haven’t previously read but is buffered in your system

Before we run the tests however we need to find which drive we will be running this. Since most machines come with 1 drive the main one which we want to test we need to find out which one it is by running the mount command. The output below will show us a lot of things but we will be looking what’s mounted in the root directory ie / simply forward slash. In this particular case as shown below the root is basically in /dev/md0 which we will use in our test later.

$ mount |grep /
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=16292488k,nr_inodes=4073122,mode=755,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=3269680k,mode=755,inode64)
/dev/md0 on / type ext4 (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)
...

If we run the command we will get the following output which shows us the speed your disk is operating at for the test.

$ sudo hdparm -t -T /dev/md0

/dev/md0:
 Timing cached reads:   38680 MB in  1.99 seconds = 19477.18 MB/sec
 Timing buffered disk reads: 802 MB in  3.01 seconds = 266.56 MB/sec

A few important things to note however here:

  • Since the drive we are testing is our main drive if there’s some activity happening in the background that’s heavy on I/O this will distort the result and have a Lower reading so ensure this is from a fresh reboot and no scheduled tasks that are heavy on disk access are currently running.
  • We are testing reads here as this is by far the most common operation performed by hdparm does not support writing. In order to do this you can simply use the dd tool in the command shown below which will basically write to a file and show you some statistics about the write speed when it completes.
    $ dd if=/dev/zero of=myfile bs=1m count=10000
  • The last point is that speed tests on the drive tend to get affected by other parameters such as:
    • Filesystem type
    • Physical state of drive (ie is it hot temperature wise)
    • Other running tasks
    • Type of disk connectivity on the main board

Keeping all these things in mind remember to re-run your tests a few time to get a good average of what the actual speed is and not in one particular instance of time.

Now that we have a way of checking our hard disk space and network speed with means of benchmarking it we need to see how we can identify the amount of memory we were allocated to ensure this is what was promised to us.

Linux offers a few simple commands to do this:

  • Free
  • Top

Those have been around since inception of unix operating systems and Linux was no exception to it but to include them. The tools are fairly straight forward to use and come in bundled with your operating system by default so you don’t need to install anything most of the times.

To run free simply run it as shown below, it takes an optional argument of -h to show the output in human readable form. What this does it basically rounds it to the closest possible multiple of your memory and appends G, M, K to make the output more readable. These days since most systems are in the Gigabyte range and as you can see below my machine has 32GB of ram.

As bonus it also shows the swap disk space which is not utilized currently since the system has not run out of memory. In most modern systems with sufficient amounts of memory you do not usually need a swap filesystem as your machine will rarely peak it’s memory usage.

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            31Gi       1.1Gi        23Gi       231Mi       6.2Gi        29Gi
Swap:          7.8Gi          0B       7.8Gi

Similar to the free command the top command is more of an interactive way of seeing the live memory and cpu changes on your system. You simply run top from the command line and the output is displayed in your screen.

$ top
top - 14:11:09 up 11 days,  9:32,  1 user,  load average: 0.02, 0.07, 0.03
Tasks: 183 total,   1 running, 182 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.5 us,  0.0 sy,  0.0 ni, 99.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  31930.5 total,  24419.7 free,   1134.9 used,   6375.9 buff/cache
MiB Swap:   8000.0 total,   8000.0 free,      0.0 used.  30097.8 avail Mem

It’s important to note that top also shows a historical load average of your system in the first line which allows you to understand the amount of load and processing that’s going on. If you see that temporarily high don’t be alarmed as it will eventually go down. If it persists then it means some process has crashed or something is happening the background that shouldn’t be happening and you should look more into it. I have written an article which you can find linked at the end of this post that explains the basic Linux commands to let you diagnose such problems.

I have also linked at the end of a tool that I wrote for a Mac but also works on Linux that lets you monitor all resources in your system using Python. It basically leverages the system kernel utilities to report and give you the information you need.

Finally checking the CPU to ensure that you got what you will be paying for is also fairly simple. You can get the information on:

  • Number of CPU cores on your machine this is shown by the first line of the output below processor: 0 (0 indicates it’s the first core)
  • Vendor and model number information
  • CPU speed, this is the most important one
  • Max CPU speed for scaling processors
  • Cache size
  • CPU identifiers

There’s also some more information there that you can find in the output below.

$ cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 158
model name	: Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz
stepping	: 9
microcode	: 0xea
cpu MHz		: 3800.000
cache size	: 8192 KB
physical id	: 0
siblings	: 8
core id		: 0
cpu cores	: 4
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple shadow_vmcs pml ept_mode_based_exec
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
bogomips	: 7599.80
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual

I’d like to add here that you can also find out the load and cpu utilization of your system using the top command that we demonstrated earlier in this article. This however is more of a live informational content on what is currently running and not the technical characteristics of your processor.

Leave a Comment

Your email address will not be published. Required fields are marked *