DB Performance Testing - The 3 Common Suites - A Step-by-Step Guide to Running sysbench
Abstract
Sharing a note I wrote in the past. The three most commonly used database testing suites are: sysbench – OLTP testing, tpch – OLAP testing, and tpcc – transaction performance testing.
This article walks you through running sysbench step by step.
The whole process is divided into:
- Introduction
- Preparation
- Compilation
- Testing
- Troubleshooting
Introduction
Here’s a passage from a foreign source to introduce sysbench:
1 | sysbench is a scriptable multi-threaded benchmark tool based on LuaJIT. It is most frequently used for database benchmarks, but can also be used to create arbitrarily complex workloads that do not involve a database server. |
Today we’ll mainly use the oltp series of tests.
Preparation
Install the required packages:
1 | yum -y install gcc gcc-c++ autoconf automake make libtool bzr mysql-devel git mysql |
Run the following commands to configure the Sysbench client so the kernel can use all CPU cores to process packets (the default is set to use 2 cores), while reducing context switching between CPU cores.
1 | sudo sh -c 'for x in /sys/class/net/eth0/queues/rx-*; do echo ffffffff>$x/rps_cpus; done' |
Note: ffffffff means using 32 cores. Adjust it according to your actual configuration—for example, for an 8-core ECS instance, enter ff.
Compilation
1 | git clone https://github.com/akopytov/sysbench.git |
Testing
A sysbench test typically looks like this, divided into 3 phases: prepare, run, and cleanup.
1 | sysbench --db-driver=mysql --mysql-host=XXX --mysql-port=XXX --mysql-user=XXX --mysql-password=XXX --mysql-db=sbtest --table_size=25000 --tables=250 --events=0 --time=600 oltp_write_only prepare |
Explanation of the options:
1 | --mysql-host IP |
The author wrote an automated testing script. Readers can download it from https://github.com/longdafeng/test/tree/master/shell/sysbench
Remember to place the script under src/lua in the sysbench source directory.
1 | cd sysbench |
Replace hostxxx, portxxx, userxxx, passwordxxx, and dbxxx with your real MySQL parameters.
This script sets different large-table sizes, different random parameters, different thread counts, and whether to enable or disable transactions, then runs the 3 integrated tests oltp_read_only, oltp_write_only, and oltp_read_write in sequence.
In the src/lua directory there are also many individual tests, such as insert, point_select, update_index, update_non_index, select_random_points, and select_random_ranges, each targeting a different scenario.
1 | [root@kudu lua]# ls *.lua |
Troubleshooting
Poor Performance
sysbench is a test that’s extremely sensitive to CPU/memory/network. I often see customers find that performance during testing differs significantly from expectations. Digging deeper, it turns out the sysbench “zombie machine” (the client) and the target database aren’t on the same LAN or in the same VPC (for cloud customers). For many cloud databases, the client machine and the target MySQL must be in the same region and the same VPC, and the connection string must use the private connection address, not the public one—public connection addresses go through many hops.
Suppose the statement is:
1 | sysbench oltp_read_write.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=sbtest --mysql-user=root --mysql-password=123456 --table_size=200000000 --tables=1 --threads=500 --events=500000 --report-interval=10 --time=0 |
no such built-in test, file or module
If, when running, you get the prompt FATAL: Cannot find benchmark ‘oltp_read_write.lua’: no such built-in test, file or module
Switch to the sysbench source directory (the path where sysbench.tar.gz was extracted):
1 | find ./ -name oltp_read_write.lua |
Then switch to the src/lua directory and run the statement again.
“Can not connect to MySQL server. Too many connections”
If, when running, the command line prompts “Can not connect to MySQL server. Too many connections” – MySQL error 1040:
1 | shell>mysql -uroot -p**** |
sysbench Won’t Run
1 | ldd /usr/bin/sysbench |
Under normal circumstances, all of sysbench’s dependent libraries should resolve correctly. If at some point a dependent library isn’t found, the most common case is that MySQL’s library isn’t found.
You need to install:
1 | yum -y install mysql-devel mysql |
Then recompile the sysbench source.
If the problem persists, you can try manually creating a link:
1 | Find it in the root directory: |
If the problem still can’t be resolved, the last resort is to download the MySQL source from GitHub, compile and install the MySQL source first, then recompile sysbench.
1 | # The --with-mysql-includes option specifies MySQL's include folder, which contains .h header files such as mysql.h. Without mysql-community-devel-version installed, there is no include folder. |