MySQL database pressure measurement
tool
The tool used here is sysbench, which is used to simulate SQL requests to measure the pressure of the database, and you can adjust the parameters of the pressure measurement according to your own needs.
Tool installation
-
Update the yum repo warehouse, otherwise the installation may fail
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
-
Use yum to install sysbench
//选择下面其中一个即可,第二个是针对权限不够时使用的 yum -y install sysbench sudo yum -y install sysbench
-
Check if the installation is successful
sysbench --version //如果出现版本号说明安装成功
Preparation before pressure measurement
First, you need to create a database by yourself, named test_db, and create the corresponding test account and password. You can call test_user
them both. After doing this, execute the following command to create the table
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare
Explain the meaning of this sysbench command:
-
–Db-driver=mysql: the driver of the database is mysql
-
--Time=300: continuous access duration, the time is 300s
-
--Threads=10: the number of threads, here is 10 threads to simulate concurrent access
-
--Report-interval=1: the interval of output results, here is 1s interval
-
--Mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user: The parameters here are the ip, port, user name and password used to connect to the database
-
mysql-db=test_db --tables=20 --table_size=1000000: The name of the target database used for pressure measurement, and the number of tables created is 20, each table constructs 1 million data, the table name is similar to sbtest1 , Sbtest2 looks like this
-
oltp_read_write: test mode, here means the execution of read and write mode
-
–Db-ps-mode=disable: Disable ps mode
Officially began to measure pressure
The types of pressure measurement are as follows:
-
read_write
sysbench command:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable run
Pressure measurement results in read-write mode:
-
read_only
sysbench command:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_only --db-ps-mode=disable run
Pressure test results in read-only mode:
-
delete
sysbench command:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_delete --db-ps-mode=disable run
Delete mode pressure test results
-
update_index
sysbench command:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_index --db-ps-mode=disable run
Follow the new index data mode:
-
update_non_index
sysbench command:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_non_index --db-ps-mode=disable run
Update the non-indexed field mode:
-
realize
sysbench命令:sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_insert --db-ps-mode=disable run
Insert mode:
-
write_only
sysbencs command:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=20 --table_size=1000000 oltp_write_only --db-ps-mode=disable run
Read only mode:
After performing the above stress test, you can clean up the previously created table. The command is as follows:
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=172.17.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable cleanup
Analysis of pressure measurement results
The following results will appear after each pressure measurement:
SQL statistics:
queries performed:
read: 0
write: 667992
other: 807208
total: 1475200
transactions: 245862 (819.44 per sec.)
queries: 1475200 (4916.73 per sec.)
ignored errors: 7 (0.02 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 300.0354s
total number of events: 245862
Latency (ms):
min: 0.79
avg: 12.20
max: 3244.74
95th percentile: 26.68
sum: 2999665.19
Threads fairness:
events (avg/stddev): 24586.2000/81.86
execution time (avg/stddev): 299.9665/0.01
Here to explain the meaning of these data:
read: How many read requests were executed during the pressure test period
write: How many write requests were executed during the pressure test period
othor: How many other requests were executed during the pressure test period
total: how many requests were executed during the pressure test period
transactions: the total number of transactions executed, in parentheses is the number of transactions executed per second
queries: The total number of requests processed, the number of requests executed per second in parentheses
ignored errors: Ignored errors
reconnects: the number of reconnects
//300.0354 was executed, and a total of 240,000+ transactions were processed
General statistics:
total time: 300.0354s
total number of events: 245862
Latency (ms):
min: 0.79 //The minimum delay in the request is 0.79ms
avg: 12.20 //The average delay in the request is 12.20ms
max: 3244.74 //The maximum delay in the request is 3244.74ms
95th percentile: 26.68 //95% of the requests are within 26.28ms
sum: 2999665.19 //Total time-consuming 2999665.19ms
The delay is 12.20ms
max: 3244.74 //The maximum delay in the request is 3244.74ms
95th percentile: 26.68 //95% of the requests are within 26.28ms
sum: 2999665.19 //Total time spent 2999665.19ms