当前位置:网站首页>MySQL toolset: the official performance testing tool mysqlslap

MySQL toolset: the official performance testing tool mysqlslap

2022-06-24 15:34:00 Wangwen'an @dba

brief introduction

MySQL As the most popular open source database , It is widely used in various fields , As a MySQL DBA, We often perform some performance tests on the database to take the initiative ( Or passive ) Make an assessment of business stress , To determine the current load and maximum performance capacity of the database .

Common performance testing tools are sysbench and tpcc, Both of these are excellent pressure measuring tools , But they all need special compilation or installation , And you need some development ability to modify the specific test statements .

mysqlslap It's with MySQL It will be installed automatically during installation , and mysqlslap The functions of many custom tests are encapsulated to the outside , Users only need to provide... Externally SQL Statement can customize the test statement , It will be easier to use .

Introduction

mysqlslap Provides a number of parameters to configure the type of project being tested , Here, only some common parameters are extracted for description , For details, please refer to mysqlslap Own help information .

Parameter name

explain

login-path=#

The new version MySQL Login method provided

-a, --auto-generate-sql

Automatic generation SQL sentence

--auto-generate-sql-add-autoincrement

Add auto incrementing columns to the automatically generated table

--auto-generate-sql-execute-number=#

In the test , perform SQL The total number of times

--auto-generate-sql-guid-primary

Generation based GUID Primary key of

--auto-generate-sql-load-type=name

Load model tested , Include mixed, update, write, key,read, The default is mix

--auto-generate-sql-secondary-indexes=#

Automatically generated tables , Number of secondary indexes

--auto-generate-sql-unique-query-number=#

In the test , Number of query statements that use unique indexes

--auto-generate-sql-unique-write-number=#

In the test , Using a unique index DML Number of statements

--auto-generate-sql-write-number=#

In the test , Each thread executes insert Number of statements , The default is 100

--commit=#

In the test , How many statements are executed once commit

-c, --concurrency=name

In the test , Number of concurrent threads / Number of clients

--create=name

Custom table creation statement , Or is it SQL File address

--create-schema=name

In the test , Database name used

--detach=#

In the test , Reconnection occurs after a certain number of statements are executed

-e, --engine=name

Specify the storage engine when creating tables

-h, --host=name

Specify the... Of the test instance host Address

-u, --user=name

Specify the user name of the test instance

-p, --password=name

Specify the password for the test instance

-P, --port=#

Specify the port of the test instance

-i, --iterations=#

Specify the number of times the test is repeated

--no-drop

Specify that the library table used for the test will not be deleted after the test is completed

-x, --number-char-cols=name

Specify the... In the test table varchar The number of columns

-y, --number-int-cols=name

Specify the... In the test table int The number of columns

--number-of-queries=#

Specifies the execution of each thread SQL Maximum number of statements ( Imprecise )

--only-print

Be similar to dry run, Output what will happen , But it will not really be implemented

-F, --delimiter=name

Use the SQL When the sentence is , Explicitly specify the separator between statements

--post-query=name

After the specified test is completed , Executed query statements , Or is it SQL Statement file

--pre-query=name

Specify before the test starts , Executed query statements , Or is it SQL Statement file

-q, --query=name

When specifying tests , Executed query statements , Or is it SQL Statement file

Practical experience

Here to mysqlslap Make a simple trial , The target instance uses Tencent cloud database MySQL, The simplest test example is as follows :

[email protected]:~# mysqlslap --concurrency=100  --iterations 10 -a  --auto-generate-sql-add-autoincrement --engine=innodb --number-of-queries=1000 -h172.1.100.10 -uroot -p
Enter password:
Benchmark
	Running for engine innodb
	Average number of seconds to run all queries: 0.046 seconds
	Minimum number of seconds to run all queries: 0.042 seconds
	Maximum number of seconds to run all queries: 0.049 seconds
	Number of clients running queries: 100
	Average number of queries per client: 10

[email protected]:~#

The simplest test model used in this example , from mysqlslap Generate all test statements and create table statements by yourself .

If you want to compare the performance under different concurrency , Can be tested in this way :

[email protected]:~# mysqlslap --concurrency=100,200 --iterations 10 -a --auto-generate-sql-add-autoincrement --engine=innodb --number-of-queries=1000 -h172.16.0.40 -uroot -p
Enter password:
Benchmark
	Running for engine innodb
	Average number of seconds to run all queries: 0.046 seconds
	Minimum number of seconds to run all queries: 0.045 seconds
	Maximum number of seconds to run all queries: 0.048 seconds
	Number of clients running queries: 100
	Average number of queries per client: 10

Benchmark
	Running for engine innodb
	Average number of seconds to run all queries: 0.037 seconds
	Minimum number of seconds to run all queries: 0.034 seconds
	Maximum number of seconds to run all queries: 0.052 seconds
	Number of clients running queries: 200
	Average number of queries per client: 5

[email protected]:~#

The output result is time , Therefore, the more time it takes, the better the overall performance .

If you want to customize the test statement , Then you can put SQL The statement is written in the file , for example :

[email protected]:~# cat create.sql
CREATE TABLE a (b int);INSERT INTO a VALUES (23);
[email protected]:~# cat query.sql
SELECT * FROM a;
SELECT b FROM a;
[email protected]:~#
[email protected]:~# mysqlslap --concurrency=100,200 --query=query.sql --create=create.sql --delimiter=";" --engine=innodb --number-of-queries=1000 -h172.16.0.40 -uroot -p
Enter password:
Benchmark
	Running for engine innodb
	Average number of seconds to run all queries: 0.045 seconds
	Minimum number of seconds to run all queries: 0.045 seconds
	Maximum number of seconds to run all queries: 0.045 seconds
	Number of clients running queries: 100
	Average number of queries per client: 10

Benchmark
	Running for engine innodb
	Average number of seconds to run all queries: 0.023 seconds
	Minimum number of seconds to run all queries: 0.023 seconds
	Maximum number of seconds to run all queries: 0.023 seconds
	Number of clients running queries: 200
	Average number of queries per client: 5

[email protected]:~#

Summary

Available on the market MySQL There are many pressure measuring tools , Each tool has its pros and cons , Learn more about tools , Then select the most appropriate tool according to the actual needs to complete the required stress test in the most efficient way .

原网站

版权声明
本文为[Wangwen'an @dba]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/05/20210511192757977a.html