Until now, in this chapter we have learned about various performance monitoring tools and commands. This recipe covers a well-known performance benchmarking tool: Sysbench. The purpose of performance benchmarking is to get a sense of system configuration and the resulting performance. Sysbench is generally used to evaluate the performance of heavy load systems. If you read the Sysbench introduction, it says that Sysbench is a benchmarking tool to evaluate a system running database under intensive load. It is also being used as a tool to evaluate the performance of multiple cloud service providers.
The current version of Sysbench supports various benchmark tests including CPU, memory, IO system, and OLTP systems. We will primarily focus on CPU, memory, and IO benchmarks.
Before using Sysbench, we will need to install it. Sysbench is available in the Ubuntu package repository with a little older (0.4.12) version. We will use the latest version (0.5) from Percona Systems, available in their repo.
To install Sysbench from the Percona repo, we need to add the repo to our installation sources. Following are the entries for Ubuntu 14.04 (trusty). Create a new file under /etc/apt/source.list.d
and add the following lines to it:
$ sudo vi /etc/apt/sources.list.d/percona.list deb http://repo.percona.com/apt trusty main deb-src http://repo.percona.com/apt trusty main
Next, add the PGP key for the preceding repo:
$ sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
Now we are ready to install the latest version of Sysbench from the Percona repo. Remember to update the apt
cache before installation:
$ sudo apt-get update $ sudo apt-get install sysbench
Once installed, you can check the installed version with the --version
flag to sysbench
:
$ sysbench --version sysbench 0.5
Now that we have Sysbench installed, let's start with performance testing our system:
--cpu-max-prime
. Also set the limit on threads with the --num-threads
option. Set the number of threads equal to the amount of CPU cores available:$ sysbench --test=cpu --num-threads=4 --cpu-max-prime=20000 run
Threads |
1 |
2 |
3 |
4 |
---|---|---|---|---|
Total time |
33.0697s |
15.4335s |
15.6258s |
15.7778s |
$ sysbench --test=memory --memory-block-size=1M --num-threads=2 --memory-total-size=100G --memory-oper=read run
--memory-hugetlb
. By default, it's set to off.fileio
test we need a few sample files to test with. Use the sysbenchprepare
command to create test files. Make sure to set a total file size greater than the size of memory to avoid caching effects. I am using a small 1GBnode with 20G disk space, so I am using 15 files of 1G each:$ sysbench --test=fileio --file-total-size=15G --file-num=15 prepare
fileio
test with different options, depending on what you want to test. The following command will perform random write operations for 60
seconds:$ sysbench --test=fileio --file-total-size=15G --file-test-mode=rndwr --max-time=60 --file-block-size=4K --file-num=15 --num-threads=1 run
--file-test-mode
to rndrd
, or to perform sequential read operations, use seqrd
. You can also combine read write operations with rndrw
or seqrewr
. Check the help menu for more options.fileio
test, execute the cleanup
command to delete all sample files:$ sysbench --test=fileio cleanup
Sysbench also supports testing MySQL performance with various tests. In the same way as the fileio
test, Sysbench takes care of setting a test environment by creating tables with data. When using Sysbench from the Percona repo, all OLTP test scripts are located at /usr/share/doc/sysbench/tests/db/
. You will need to specify the full path when using these scripts. For example:
$ sysbench --test=oltp
The preceding command will change to the following:
$ sysbench --test=/usr/share/doc/sysbench/tests/db/ol1tp.lua
Sysbench output can be hard to analyze and compare, especially with multiple runs. This is where graphs come in handy. You can try to set up your own graphing mechanism, or simply use prebuilt scripts to create graphs for you. A quick Google search gave me two good, looking options:
There are various other performance testing frameworks available. Phoronix Test Suite, Unixbench, and Perfkit by Google are some popular names. Phoronix Test Suite focuses on hardware performance and provides a wide range of performance analysis options, whereas Unixbench provides an option to test various Linux systems. Google open-sourced their performance toolkit with a benchmarker and explorer to evaluate various cloud systems.