MySQL/MariaDB数据库的性能测试

摘要:
否则将追究法律责任。一.数据库服务衡量指标qps:querypersecondtps:transactionpersecond二.压力测试工具mysqlslap:  Mariadb自带的测试脚本Sysbench:功能强大  https://github.com/akopytov/sysbenchtpcc-mysqlMySQLBenchmarkSuiteMySQLsuper-smackMyBench三.Mysqlslap使用案例1˃.Mysqlslap概述Mysqlslap:来自于mariadb包,测试的过程默认生成一个mysqlslap的schema,生成测试表t1,查询和插入测试数据,mysqlslap库自动生成,如果已经存在则先删除。

MySQL/MariaDB数据库的性能测试

作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.数据库服务衡量指标

qps: 
query per second(每秒支持多少查询)
tps:
transaction per second(每秒支持多少个事务性能)

二.压力测试工具

mysqlslap:
  Mariadb自带的测试脚本
Sysbench:功能强大   https:
//github.com/akopytov/sysbench
tpcc-mysql
MySQL Benchmark Suite
MySQL super
-smack
MyBench

三.Mysqlslap使用案例

1>.Mysqlslap概述

Mysqlslap:
来自于mariadb包,测试的过程默认生成一个mysqlslap的schema,生成测试表t1,查询和插入测试数据,mysqlslap库自动生成,如果已经存在则先删除。用--only-print来打印实际的测试过程,整个测试完成后不会在数据库中留下痕迹
使用格式:
mysqlslap [options]

2>.Mysqlslap常用参数 [options] 说明:

--auto-generate-sql, -a 
自动生成测试表和数据,表示用mysqlslap工具自己生成的SQL脚本来测试并发压力   
--auto-generate-sql-load-type=type
测试语句的类型。代表要测试的环境是读操作还是写操作还是两者混合的。取值包括:read,key,write,update和mixed(默认) --auto-generate-sql-add-auto-increment
代表对生成的表自动添加auto_increment列,从5.1.18版本开始支持
--number-char-cols=N, -x N
自动生成的测试表中包含多少个字符类型的列,默认1
--number-int-cols=N, -y N
自动生成的测试表中包含多少个数字类型的列,默认1
--number-of-queries=N
总的测试查询次数(并发客户数×每客户查询次数)
--query=name,-q
使用自定义脚本执行测试,例如可以调用自定义的存储过程或者sql语句来执行测试
--create-schema
代表自定义的测试库名称,测试的schema
--commint=N
多少条DML后提交一次
--compress, -C
如服务器和客户端都支持压缩,则压缩信息
--concurrency=N, -c N
表示并发量,即模拟多少个客户端同时执行select。可指定多个值,以逗号或者--delimiter参数指定值做为分隔符   如:--concurrency=100,200,500--engine=engine_name, -e engine_name
代表要测试的引擎,可以有多个,用分隔符隔开。例如:--engines=myisam,innodb
--iterations=N, -i N
测试执行的迭代次数,代表要在不同并发环境下,各自运行测试多少次
--only-print
只打印测试语句而不实际执行。
--detach=N
执行N条语句后断开重连
--debug-info, -T
打印内存和CPU的相关信息
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第2张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap --help
mysqlslap  Ver 1.0 Distrib 5.5.64-MariaDB, forLinux (x86_64)
Copyright (c) 2005, 2018, Oracle, MariaDB Corporation Ab and others.
Run a query multiple times against the server.
Usage: mysqlslap [OPTIONS]
Default options are read from the following files inthe given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf 
The following groups are read: mysqlslap client client-server client-mariadb
The following options may be given as the first argument:
--print-defaults          Print the program argument list and exit.
--no-defaults             Don't read default options from any option file.
The following specify which files/extra groupsare read (specified before remaining options):
--defaults-file=#         Only read default options from the given file#.
--defaults-extra-file=#   Read this fileafter the global files are read.
--defaults-group-suffix=# Additionally read default groupswith # appended as a suffix.
  -?, --help          Display this help and exit.
  -a, --auto-generate-sql 
                      Generate SQL where not supplied by fileor command line.
  --auto-generate-sql-add-autoincrement 
                      Add an AUTO_INCREMENT column to auto-generated tables.
  --auto-generate-sql-execute-number=# 
                      Set this number to generate a set number of queries to
                      run.
  --auto-generate-sql-guid-primary 
                      Add GUID based primary keys to auto-generated tables.
  --auto-generate-sql-load-type=name 
                      Specify test load type: mixed, update, write, key, or
                      read; default is mixed.
  --auto-generate-sql-secondary-indexes=# 
                      Number of secondary indexes to add to auto-generated
                      tables.
  --auto-generate-sql-unique-query-number=# 
                      Number of unique queries to generate forautomatic tests.
  --auto-generate-sql-unique-write-number=# 
                      Number of unique queries to generate for
                      auto-generate-sql-write-number.
  --auto-generate-sql-write-number=# 
                      Number of row inserts to perform foreach thread (default
                      is 100).
  --commit=#          Commit records every X number of statements.
  -C, --compress      Use compression in server/client protocol.
  -c, --concurrency=name 
                      Number of clients to simulate forquery to run.
  --create=name       File or stringto use create tables.
  --create-schema=name 
                      Schema to run tests in.
  --csv[=name]        Generate CSV output to named file or to stdout if no file
                      is named.
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  --debug-check       Check memory and open fileusage at exit.
  -T, --debug-info    Print some debug infoat exit.
  --default-auth=name Default authentication client-side plugin to use.
  -F, --delimiter=name 
                      Delimiter to use in SQL statements supplied in fileor
                      command line.
  --detach=#          Detach (close and reopen) connections after X number of
                      requests.
  -e, --engine=name   Comma separated list of storage engines to use for
                      creating the table. The test is run foreach engine. You
                      can also specify an option for an engine after a `:',
                      like memory:max_row=2300
  -h, --host=name     Connect to host.
  --init-command=name SQL Command to execute when connecting to MySQL server.
                      Will automatically be re-executed when reconnecting.
  -i, --iterations=#  Number of times to run the tests.
  --no-drop           Do not drop the schema after the test.
  -x, --number-char-cols=name 
                      Number of VARCHAR columns to create in table if
                      specifying --auto-generate-sql.
  -y, --number-int-cols=name 
                      Number of INT columns to create in table ifspecifying
                      --auto-generate-sql.
  --number-of-queries=# 
                      Limit each client to this number of queries (this is not
                      exact).
  --only-print        Do not connect to the databases, but instead print out
                      what would have been done.
  -p, --password[=name] 
                      Password to use when connecting to server. If password is
                      not given it's asked from the tty.
  --plugin-dir=name   Directory for client-side plugins.
  -P, --port=#        Port number to use forconnection.
  --post-query=name   Query to run or filecontaining query to execute after
                      tests have completed.
  --post-system=name  system() stringto execute after tests have completed.
  --pre-query=name    Query to run or filecontaining query to execute before
                      running tests.
  --pre-system=name   system() stringto execute before running tests.
  --protocol=name     The protocol to use forconnection (tcp, socket, pipe,
                      memory).
  -q, --query=name    Query to run or filecontaining query to run.
  -s, --silent        Run program in silent mode -no output.
  -S, --socket=name   The socket file to use forconnection.
  --ssl               Enable SSL forconnection (automatically enabled with
                      other flags).
  --ssl-ca=name       CA file inPEM format (check OpenSSL docs, implies
                      --ssl).
  --ssl-capath=name   CA directory (check OpenSSL docs, implies --ssl).
  --ssl-cert=name     X509 cert in PEM format (implies --ssl).
  --ssl-cipher=name   SSL cipher to use (implies --ssl).
  --ssl-key=name      X509 key in PEM format (implies --ssl).
  --ssl-verify-server-cert 
                      Verify server's "Common Name" in its cert against
                      hostnameused when connecting. This option is disabled by
                      default.
  -u, --user=name     User for login ifnot current user.
  -v, --verbose       More verbose output; you can use this multiple times to
                      get even moreverbose output.
  -V, --version       Output version information and exit.
Variables (--variable-name=value)
and boolean options {FALSE|TRUE}      Value (after reading options)
------------------------------------- ------------------------------------
auto-generate-sql                     FALSE
auto-generate-sql-add-autoincrement   FALSE
auto-generate-sql-execute-number      0
auto-generate-sql-guid-primary        FALSE
auto-generate-sql-load-type           mixed
auto-generate-sql-secondary-indexes   0
auto-generate-sql-unique-query-number 10
auto-generate-sql-unique-write-number 10
auto-generate-sql-write-number        100
commit                                0
compress                              FALSE
concurrency                           (No default value)
create                                (No default value)
create-schema                         mysqlslap
debug-check                           FALSE
debug-infoFALSE
default-auth                          (No default value)
delimiter                             
detach                                0
engine                                (No default value)
host                                  (No default value)
init-command                          (No default value)
iterations                            1
no-drop                               FALSE
number-char-cols                      (No default value)
number-int-cols                       (No default value)
number-of-queries                     0
only-print                            FALSE
plugin-dir(No default value)
port                                  3306
post-query                            (No default value)
post-system                           (No default value)
pre-query                             (No default value)
pre-system                            (No default value)
query                                 (No default value)
silent                                FALSE
socket                                (No default value)
ssl                                   FALSE
ssl-ca                                (No default value)
ssl-capath                            (No default value)
ssl-cert                              (No default value)
ssl-cipher                            (No default value)
ssl-key                               (No default value)
ssl-verify-server-cert                FALSE
user                                  (No default value)
verbose                               (No default value)
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap --help      #更多选项可参考帮助信息

3>.单线程测试

MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第4张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie
Benchmark
    Average number of seconds to run all queries: 0.003seconds
    Minimum number of seconds to run all queries: 0.003seconds
    Maximum number of seconds to run all queries: 0.003seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie

4>.多线程测试(使用–concurrency来模拟并发连接)

MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第6张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -c 100
Benchmark
    Average number of seconds to run all queries: 0.653seconds
    Minimum number of seconds to run all queries: 0.653seconds
    Maximum number of seconds to run all queries: 0.653seconds
    Number of clients running queries: 100
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -c 100

5>.迭代测试(用于需要多次执行测试得到平均值)

MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第8张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -i 10
Benchmark
    Average number of seconds to run all queries: 0.002seconds
    Minimum number of seconds to run all queries: 0.002seconds
    Maximum number of seconds to run all queries: 0.003seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -i 10
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第10张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie --auto-generate-sql-add-autoincrement
Benchmark
    Average number of seconds to run all queries: 0.002seconds
    Minimum number of seconds to run all queries: 0.002seconds
    Maximum number of seconds to run all queries: 0.002seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie --auto-generate-sql-add-autoincrement
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第12张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -a --auto-generate-sql-load-type=read
Benchmark
    Average number of seconds to run all queries: 0.001seconds
    Minimum number of seconds to run all queries: 0.001seconds
    Maximum number of seconds to run all queries: 0.001seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -a --auto-generate-sql-load-type=read
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第14张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -a auto-generate-sql-secondary-indexes=3
Benchmark
    Average number of seconds to run all queries: 0.003seconds
    Minimum number of seconds to run all queries: 0.003seconds
    Maximum number of seconds to run all queries: 0.003seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -a auto-generate-sql-secondary-indexes=3
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第16张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --auto-generate-sql-write-number=1000
Benchmark
    Average number of seconds to run all queries: 0.007seconds
    Minimum number of seconds to run all queries: 0.007seconds
    Maximum number of seconds to run all queries: 0.007seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --auto-generate-sql-write-number=1000
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第18张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie --create-schema mysql -q "select count(*) from user"
Benchmark
    Average number of seconds to run all queries: 0.000seconds
    Minimum number of seconds to run all queries: 0.000seconds
    Maximum number of seconds to run all queries: 0.000seconds
    Number of clients running queries: 1
    Average number of queries per client: 1
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie --create-schema mysql -q "select count(*) from user"
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第20张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a -e innodb
Benchmark
    Running forengine innodb
    Average number of seconds to run all queries: 0.003seconds
    Minimum number of seconds to run all queries: 0.003seconds
    Maximum number of seconds to run all queries: 0.003seconds
    Number of clients running queries: 1
    Average number of queries per client: 0
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a -e innodb
MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第22张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --number-of-queries=10
Benchmark
    Average number of seconds to run all queries: 0.003seconds
    Minimum number of seconds to run all queries: 0.003seconds
    Maximum number of seconds to run all queries: 0.003seconds
    Number of clients running queries: 1
    Average number of queries per client: 10
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --number-of-queries=10

6>.测试同时不同的存储引擎的性能进行对比

MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第24张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-infoBenchmark
    Running forengine myisam
    Average number of seconds to run all queries: 0.081seconds
    Minimum number of seconds to run all queries: 0.080seconds
    Maximum number of seconds to run all queries: 0.083seconds
    Number of clients running queries: 50
    Average number of queries per client: 20
Benchmark
    Running forengine myisam
    Average number of seconds to run all queries: 0.183seconds
    Minimum number of seconds to run all queries: 0.081seconds
    Maximum number of seconds to run all queries: 0.583seconds
    Number of clients running queries: 100
    Average number of queries per client: 10
Benchmark
    Running forengine innodb
    Average number of seconds to run all queries: 0.110seconds
    Minimum number of seconds to run all queries: 0.097seconds
    Maximum number of seconds to run all queries: 0.130seconds
    Number of clients running queries: 50
    Average number of queries per client: 20
Benchmark
    Running forengine innodb
    Average number of seconds to run all queries: 0.118seconds
    Minimum number of seconds to run all queries: 0.111seconds
    Maximum number of seconds to run all queries: 0.126seconds
    Number of clients running queries: 100
    Average number of queries per client: 10
User time 0.77, System time 0.46
Maximum resident set size 10628, Integral resident set size 0
Non-physical pagefaults 13187, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 46331, Involuntary context switches 29
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-infoBenchmark

7>.执行一次测试,分别50和100个并发,执行1000次总查询

MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第26张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=50,100 --number-of-queries 1000 --debug-info
Benchmark
    Average number of seconds to run all queries: 0.197seconds
    Minimum number of seconds to run all queries: 0.197seconds
    Maximum number of seconds to run all queries: 0.197seconds
    Number of clients running queries: 50
    Average number of queries per client: 20
Benchmark
    Average number of seconds to run all queries: 0.121seconds
    Minimum number of seconds to run all queries: 0.121seconds
    Maximum number of seconds to run all queries: 0.121seconds
    Number of clients running queries: 100
    Average number of queries per client: 10
User time 0.10, System time 0.05
Maximum resident set size 9744, Integral resident set size 0
Non-physical pagefaults 3967, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 5373, Involuntary context switches 15
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=50,100 --number-of-queries 1000 --debug-info

8>.50和100个并发分别得到一次测试结果(Benchmark),并发数越多,执行完所有查询的时间越长。为了准确起见,可以多迭代测试几次

MySQL/MariaDB数据库的性能测试第1张MySQL/MariaDB数据库的性能测试第28张
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --debug-info
Benchmark
    Average number of seconds to run all queries: 0.201seconds
    Minimum number of seconds to run all queries: 0.098seconds
    Maximum number of seconds to run all queries: 0.595seconds
    Number of clients running queries: 50
    Average number of queries per client: 20
Benchmark
    Average number of seconds to run all queries: 0.123seconds
    Minimum number of seconds to run all queries: 0.113seconds
    Maximum number of seconds to run all queries: 0.138seconds
    Number of clients running queries: 100
    Average number of queries per client: 10
User time 0.38, System time 0.27
Maximum resident set size 10600, Integral resident set size 0
Non-physical pagefaults 8716, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 26126, Involuntary context switches 19
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --debug-info

免责声明:文章转载自《MySQL/MariaDB数据库的性能测试》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇linux下jcmd无法获取jvmdumpjava命令--jmap命令使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

关于MYSQL字符集问题(一)

  MySQL的字符集支持(Character Set Support)有两个方面:     字符集(Character set)和排序方式(Collation)。   对于字符集的支持细化到四个层次:     服务器(server),数据库(database),数据表(table)和连接(connection)。MySQL默认字符集   MySQL对于...

【转】MySQL各版本的区别

来源:https://www.cnblogs.com/langtianya/p/5185601.html MySQL各版本的区别: 1. MySQL Community Server 社区版本,开源免费,但不提供官方技术支持。2. MySQL Enterprise Edition 企业版本,需付费,可以试用30天。3. MySQL Cluster 集群版,...

Linux配置Mysql的主备搭建

前提声明:linux为redhat7.5,mysql为5.7.33      主机IP(Master):192.168.122.131         从机IP(Slave):192.168.122.132 mysql安装包链接和操作文档: 链接:https://pan.baidu.com/s/1dJX2NZ0Gc8fn_BQIRS8aSQ提取码:1234...

MySQL-Linux升级MySQL

升级MySql5.7.26 到5.7.29 1、查看原MySQL版本 select version(); 2、备份原数据库 以test数据库为例。 mysqldump -u root -pP@ssw0rd_2770 test > /opt/mysql/bak/test.sql 3、下载MySQL最新版本 wget http://dev.mysq...

更换Mariadb库为mysql 5.7

https://www.cnblogs.com/get-rich/articles/10623208.html entOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用MariaDB代替了,MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将M...

MySql免安装版安装配置,附MySQL服务无法启动解决方案

文首提要: 我下载的MySQL版本是:mysql-5.7.17-winx64.zip Archive版;系统:Windows7 64位。 一、解压文件 下载好MySQL后,解压到D盘下,也可以根据个人喜好解压在其他盘符的路径下,解压后的路径是:D:mysql-5.7.17-winx64。解压好后不要太兴奋,需要配置默认文件呢! 二、配置默认文件 解压后的文...