A must-have performance test for architects--Installation and use of the database pressure testing tool sysbench

Sysbench is an open source multi-threaded performance testing tool that can perform performance tests on CPU/memory/thread/IO/database, etc.

As a developer, you need to understand the performance of the service. qps, tps, rt, etc. are the basic performance indicators for testing a service. This article focuses on the pressure measurement process and performance indicators of the database from the installation and actual testing of sysbench. information

1. sysbench software installation

Installation is divided into two situations: online installation and offline installation

  • 1.1 Online installation (centos system):
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash	

sudo dnf -y install sysbench

Different systems can refer to the official link for installation : sysbench open source git address

  • 1.2 Offline installation

1. Put the installation package on the server and decompress it

tar -xvzf sysbench-xxxx.tar.gz

Installation package download address : sysbench1.0.20 package

2. Install related components

yum install m4 autoconf automake libtool

yum -y install mysql-devel(mysql数据库依赖库,其他数据库要换成对应的xxx-devel)

3. Run the auto-generated script

./autogen.sh
如果没权限用chmod +x autogen.sh命令修改

4. Check and install and compile

./configure

make && make install

5. Verify whether the installation is successful

进入到安装目录,执行命令
cd /usr/bin/

./sysbench --version

So far, the installation process has been completed, and you can see the relevant script files in the /usr/share/sysbench directory

2. Performance testing process

This article takes the test database test as an example to illustrate, roughly divided into three steps, prepare (build database and table and initialize data stage), run (test stage) and cleanup (clear database table and corresponding data information) stage

2.1 Initialization

First, go to the sysbench installation directory

cd /usr/bin

Run the following initialization command. Before executing the command, you need to create the sbtest database on the database in advance, because the default connection in the lua script is the database. If the library does not exist, the corresponding command may report an error

sysbench \ 
--mysql-host=${tidb_host} \ 
--mysql-port=4000 \ 
--mysql-user=root \ 
--mysql-db=sbtest \ 
--time=100 \ 
--threads=16 \ 
--report-interval=10 \ 
--db-driver=mysql \ 
--rand-type=uniform \ 
--rand-seed=$RANDOM \ 
--tables=16 \ 
--table-size=10000000 
\ oltp_common 
\ prepare

The parameters in the command line are set according to your actual situation. If the database uses haproxy for load proxy, the corresponding host and port are replaced with the port of the load. The above corresponds to the port of the tidb database.

In the above command, the meaning is to create 16 tables. Each table has 1000w rows of data. The runtime reports real-time performance every 10 seconds. There are 16 threads for concurrent access. The total running time is 100 seconds, and others represent database connection information

2.2 Data Preheating

sysbench \ 
--mysql-host=${tidb_host} \ 
--mysql-port=4000 \ 
--mysql-user=root \ 
--mysql-db=sbtest \ 
--time=100 \ 
--threads=16 \ 
--report-interval=10 \ 
--db-driver=mysql \ 
--rand-type=uniform \ 
--rand-seed=$RANDOM \ 
--tables=16 \ 
--table-size=10000000 \ 
oltp_common \ 
prewarm

2.3 Pressure test

sysbench \
  --mysql-host=${tidb_host} \
  --mysql-port=4000 \
  --mysql-user=root \
  --mysql-db=sbtest \
  --time=100 \
  --threads=${threads} \
  --report-interval=10 \
  --db-driver=mysql \
  --rand-type=uniform \
  --rand-seed=$RANDOM \
  --tables=16 \
  --table-size=10000000 \
  ${test} \
  run

t e s t 变量换成 s y s b e n c h 对应的 l u a 脚本名称,可以在 / u s r / s h a r e / s y s b e n c h 目录下查看脚本名称,可以分别测试下 o l t p p o i n t s e l e c t o l t p u p d a t e i n d e x o l t p u p d a t e n o n i n d e x o l t p r e a d w r i t e 几种情况下的性能指标,将 The {test} variable is replaced with the lua script name corresponding to sysbench. You can view the script name in the /usr/share/sysbench directory. You can test the performance indicators of oltp_point_select, oltp_update_index, oltp_update_non_index, and oltp_read_write respectively. {test} with the corresponding name and execute it multiple times to see the output information of the console, such as

sysbench \
  --mysql-host=${tidb_host} \
  --mysql-port=4000 \
  --mysql-user=root \
  --mysql-db=sbtest \
  --time=100 \
  --threads=${threads} \
  --report-interval=10 \
  --db-driver=mysql \
  --rand-type=uniform \
  --rand-seed=$RANDOM \
  --tables=16 \
  --table-size=10000000 \
  oltp_point_select \
  run

2.4 Clear data

sysbench \
  --mysql-host=${tidb_host} \
  --mysql-port=4000 \
  --mysql-user=root \
  --mysql-password='xxxxxx' \
  --mysql-db=sbtest \
  --time=100 \
  --threads=16 \
  --report-interval=20 \
  --db-driver=mysql \
  --rand-type=uniform \
  --rand-seed=$RANDOM \
  --tables=16 \
  --table-size=10000000 \
  oltp_common \
  cleanup

Well, the database testing process is basically these. For the newly built database service, you can refer to the entire process to conduct a simple performance stress test, so as to have a general understanding of the basic index information of the database. If this article is helpful to you, I hope it can be a three-in-one

Guess you like

Origin juejin.im/post/7264921418802462754