Benchmarking and stress testing is sometime necessary to optimize system performance and remove system bottlenecks caused by hardware. In a Linux system , this could be done easily with few basic command line tools.
There are many all in one dedicated benchmarking tool with a pretty GUI available for Linux. But here we are focusing on simple command line tools only and going to test the followings listed bellow.
- CPU stress testing and benchmarking.
- Hard drive I/O performance testing.
- Network performance and speed testing.
- OpenSSL performance testing.
- RAM speed testing.
Have a look at this guide for a detailed GPU benchmarking and stress testing.
ContentsShow / Hide
1. CPU Benchmark and stress testing
Prime number calculation test within a given range with sysbench,
sysbench --test=cpu --num-threads=4 --cpu-max-prime=9999 run
this command will calculate all prime numbers within 9999, change the number 9999 if you wish.
Integer calculation performance test with one-line command
time $(i=0; while (( i < 9999999 )); do (( i ++ )); done)
this will return the the time required to crunch the integers between 0 to 9999999.
real 0m47.354s user 0m47.328s sys 0m0.000s
Single threaded CPU stress testing
the /dev/urandom file is a special type of device file, which returns random junk characters endlessly, so calculating md5 hash of /dev/urandom is basically stressing the CPU.
Multi threaded CPU stress testing
Enjoy free shipping and One-Day delivery, cancel any time.
This command is to impose a multi threaded load on the CPU for 5minuite,
stress --cpu 4 --timeout 300s
--cpu 4 value according to your system, if you have a quad core 8 threaded CPU, then use
--cpu 8 .
2. Hard drive I/O performance testing
Hard drive I/O performance have a great impact on Linux system performance and user experience. Simply faster HDD means better user experience and in most cases, hard drive I/O speed is more important than CPU and RAM speed.
HDD raw read speed test
A vary simple raw hard drive read speed could be determined with cat and pipebench . This command requires root privilege, so run it as a root user or use sudo.
cat /dev/sda3 | pipebench -q > /dev/null
HDD file write speed test with dd
dd bs=16k count=102400 oflag=direct if=/dev/zero of=test_data
This will create a file of round 1.6 GB containing only zeros, at the present directory and will give you an overview of your HDD write speed.
HDD file read speed test with dd
Now we will use the test_data file created in the above step to determine HDD read speed.
dd bs=16K count=102400 iflag=direct if=test_data of=/dev/null
This command will read the test_data file and throug the data to a black hole like special device file,
Direct drive read speed test with hdparm
sudo hdparm -t /dev/sda
This test returns timing buffered disk read speed and this result could be assumed as the fastest disk read speed.
note: In Linux, it is common that native filesystems (ext4, btrfs, xfs etc.) always tends to perform better than other third party filesystems like Windows NTFS or Mac HFS+ .
3. Network performance and speed testing
Network interface throughput measurement and benchmarking is very common for networking devices like routers, bridges, hubs etc. Everyone want the best speed out of their network, so it's necessary to benchmark and optimize the network.
Simple network throughput measurement with iperf .
Before going further we've to make some assumptions according to the network setup.
While writing this, my network's IPv4 address was in the 220.127.116.11/24 range. The server IP address was 192.168.72.1 and the client PC was 192.168.1.4 So, you've to modify these settings according to your network setup.
- First start a iperf server in the server machine,
iperf -s -p 8000
this will start a iperf in server mode, which binds port 8080 with all available network interfaces.
- Now connect to that server with iperf as client, just find the correct server IP address and run the command bellow
iperf -c 192.168.72.1 -p 8000
this will give you overview of your networks tcp connection throughput speed.
4. Network speed test with ncmeter
Ncmeter is a simple bash shell script which uses netcat-traditional to measure data throughput of a network. This scripts is a part of the netcat-traditional package in Debian based distros, located at the /usr/share/doc/netcat-traditional/examples/contrib folder. Copy that script to /usr/local/bin , make it executable with chmod +x and then run the script.
cp /usr/share/doc/netcat-traditional/examples/contrib/ncmeter ~/ chmod +x ~/ncmeter ./ncmeter --help # show available options
Start the ncmeter in server mode
which binds all available network interfaces with port 23457.
Open up a new terminal or new tab then run the following command.
./ncmeter 192.168.72.1 256M
Replace the IP 192.168.72.1 with your ncmeter servers IP.
5. OpenSSL benchmark testing
This test basically means how fast the CPU can calculate cryptographic hashes like md5, sha1, aes, rsa etc. etc. OpenSSL benchmark is also important for networking devices like routers, bridges, hubs etc.
OpenSSL benchmarking could be done easily with the commands bellow.
openssl speed des des-ede3 dsa2048 hmac idea-cbc md5
This performance varies greatly if there is any hardware cryptographic accelerator present in the CPU, for more detail see the openssl man page and openssl website.
6. RAM speed testing
STREAM is the de facto industry standard tool for testing RAM speed. However it's not in the Ubuntu's repository. So, you've to compile it yourself to do the test.
I'm not going into the details of how to compile a software on Linux with command line tools. Just the commands for any Debian based system and and little comments after them.
- Install some essential tools for binary compiling.
sudo apt-get install git g++ build-essential pkg-config
- Copy the repository of STREAM.
git clone https://github.com/jeffhammond/STREAM.git
- Go to the directory and compile.
cd STREAM/ && make all
- Test the C version of the application.
Well, that's it, a screenshot of the results below, average speed was above 10 GB/s with all the 4 CPU threads being used.
I don't have any system with a modern 1600 MHz DDR3L RAM or with a 2400 MHz DDR4 RAM, if you have one please do this test share your experience.
RAM speed testing with dd
dd unix tool isn't exactly for testing RAM speed, it's also unnecessary to do such testing however this may be considered as an experiment.
tmpfs is a RAM based super fast file system, something like a ramdisk, so by doing a read write speed test on a tmpfs mounted folder will give a rough idea about RAM speed. So, lets have a look at commands bellow.
mkdir RAM_test sudo mount tmpfs -t tmpfs RAM_test/ # mount the tmpfs filesystem cd RAM_test dd if=/dev/zero of=data_tmp bs=1M count=512 # write to RAM test dd if=data_tmp of=/dev/null bs=1M count=512
Look at the result ! It's incredibly fast ! I achieved around 2.8 GB/s write speed and 3.8 GB/s read speed with a 4GB 1333 MHz DDR3 RAM module. You can find out more about linux memory usage here.
So, that's it, simple benchmark test in Linux, this will give you a rough overview of your system performance. This methods should work perfectly on wide range of UNIX or GNU/Linux distributions.
Though benchmarking results could vary test by test as system performance depends upon many things like currently running applications, background tasks even on ambient temperature.
If you have any further question, feel free to ask it and also don't forget to share this tutorial with your friends.