MySQL/MariaDB数据库的性能测试
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..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=,, --engine=engine_name, -e engine_name
代表要测试的引擎,可以有多个,用分隔符隔开。例如:--engines=myisam,innodb --iterations=N, -i N
测试执行的迭代次数,代表要在不同并发环境下,各自运行测试多少次 --only-print
只打印测试语句而不实际执行。 --detach=N
执行N条语句后断开重连 --debug-info, -T
打印内存和CPU的相关信息
[root@node103.yinzhengjie.org.cn ~]# mysqlslap --help
mysqlslap Ver 1.0 Distrib 5.5.-MariaDB, for Linux (x86_64)
Copyright (c) , , 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 in the 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 groups are read (specified before remaining options):
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# Additionally read default groups with # appended as a suffix. -?, --help Display this help and exit.
-a, --auto-generate-sql
Generate SQL where not supplied by file or 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 for automatic 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 for each thread (default
is ).
--commit=# Commit records every X number of statements.
-C, --compress Use compression in server/client protocol.
-c, --concurrency=name
Number of clients to simulate for query to run.
--create=name File or string to 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 file usage at exit.
-T, --debug-info Print some debug info at exit.
--default-auth=name Default authentication client-side plugin to use.
-F, --delimiter=name
Delimiter to use in SQL statements supplied in file or
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 for each engine. You
can also specify an option for an engine after a `:',
like memory:max_row=
-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 if specifying
--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 for connection.
--post-query=name Query to run or file containing query to execute after
tests have completed.
--post-system=name system() string to execute after tests have completed.
--pre-query=name Query to run or file containing query to execute before
running tests.
--pre-system=name system() string to execute before running tests.
--protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-q, --query=name Query to run or file containing query to run.
-s, --silent Run program in silent mode - no output.
-S, --socket=name The socket file to use for connection.
--ssl Enable SSL for connection (automatically enabled with
other flags).
--ssl-ca=name CA file in PEM 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
hostname used when connecting. This option is disabled by
default.
-u, --user=name User for login if not current user.
-v, --verbose More verbose output; you can use this multiple times to
get even more verbose 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
auto-generate-sql-guid-primary FALSE
auto-generate-sql-load-type mixed
auto-generate-sql-secondary-indexes
auto-generate-sql-unique-query-number
auto-generate-sql-unique-write-number
auto-generate-sql-write-number
commit
compress FALSE
concurrency (No default value)
create (No default value)
create-schema mysqlslap
debug-check FALSE
debug-info FALSE
default-auth (No default value)
delimiter detach
engine (No default value)
host (No default value)
init-command (No default value)
iterations
no-drop FALSE
number-char-cols (No default value)
number-int-cols (No default value)
number-of-queries
only-print FALSE
plugin-dir (No default value)
port
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>.单线程测试
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie
Benchmark
Average number of seconds to run all queries: 0.003 seconds
Minimum number of seconds to run all queries: 0.003 seconds
Maximum number of seconds to run all queries: 0.003 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie
4>.多线程测试(使用–concurrency来模拟并发连接)
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -c
Benchmark
Average number of seconds to run all queries: 0.653 seconds
Minimum number of seconds to run all queries: 0.653 seconds
Maximum number of seconds to run all queries: 0.653 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -c 100
5>.迭代测试(用于需要多次执行测试得到平均值)
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -i
Benchmark
Average number of seconds to run all queries: 0.002 seconds
Minimum number of seconds to run all queries: 0.002 seconds
Maximum number of seconds to run all queries: 0.003 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -i 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.002 seconds
Minimum number of seconds to run all queries: 0.002 seconds
Maximum number of seconds to run all queries: 0.002 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie --auto-generate-sql-add-autoincrement
[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.001 seconds
Minimum number of seconds to run all queries: 0.001 seconds
Maximum number of seconds to run all queries: 0.001 seconds
Number of clients running queries:
Average number of queries per client: [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
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -a -uroot -pyinzhengjie -a auto-generate-sql-secondary-indexes=
Benchmark
Average number of seconds to run all queries: 0.003 seconds
Minimum number of seconds to run all queries: 0.003 seconds
Maximum number of seconds to run all queries: 0.003 seconds
Number of clients running queries:
Average number of queries per client: [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
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --auto-generate-sql-write-number=
Benchmark
Average number of seconds to run all queries: 0.007 seconds
Minimum number of seconds to run all queries: 0.007 seconds
Maximum number of seconds to run all queries: 0.007 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --auto-generate-sql-write-number=1000
[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.000 seconds
Minimum number of seconds to run all queries: 0.000 seconds
Maximum number of seconds to run all queries: 0.000 seconds
Number of clients running queries:
Average number of queries per client: [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"
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a -e innodb
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.003 seconds
Minimum number of seconds to run all queries: 0.003 seconds
Maximum number of seconds to run all queries: 0.003 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a -e innodb
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --number-of-queries=
Benchmark
Average number of seconds to run all queries: 0.003 seconds
Minimum number of seconds to run all queries: 0.003 seconds
Maximum number of seconds to run all queries: 0.003 seconds
Number of clients running queries:
Average number of queries per client: [root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --number-of-queries=10
6>.测试同时不同的存储引擎的性能进行对比
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=, --number-of-queries --iterations= --engine=myisam,innodb --debug-infoBenchmark
Running for engine myisam
Average number of seconds to run all queries: 0.081 seconds
Minimum number of seconds to run all queries: 0.080 seconds
Maximum number of seconds to run all queries: 0.083 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.183 seconds
Minimum number of seconds to run all queries: 0.081 seconds
Maximum number of seconds to run all queries: 0.583 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.110 seconds
Minimum number of seconds to run all queries: 0.097 seconds
Maximum number of seconds to run all queries: 0.130 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.118 seconds
Minimum number of seconds to run all queries: 0.111 seconds
Maximum number of seconds to run all queries: 0.126 seconds
Number of clients running queries:
Average number of queries per client: User time 0.77, System time 0.46
Maximum resident set size , Integral resident set size
Non-physical pagefaults , Physical pagefaults , Swaps
Blocks in out , Messages in out , Signals
Voluntary context switches , Involuntary context switches
[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次总查询
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=, --number-of-queries --debug-info
Benchmark
Average number of seconds to run all queries: 0.197 seconds
Minimum number of seconds to run all queries: 0.197 seconds
Maximum number of seconds to run all queries: 0.197 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Average number of seconds to run all queries: 0.121 seconds
Minimum number of seconds to run all queries: 0.121 seconds
Maximum number of seconds to run all queries: 0.121 seconds
Number of clients running queries:
Average number of queries per client: User time 0.10, System time 0.05
Maximum resident set size , Integral resident set size
Non-physical pagefaults , Physical pagefaults , Swaps
Blocks in out , Messages in out , Signals
Voluntary context switches , Involuntary context switches
[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),并发数越多,执行完所有查询的时间越长。为了准确起见,可以多迭代测试几次
[root@node103.yinzhengjie.org.cn ~]# mysqlslap -uroot -pyinzhengjie -a --concurrency=, --number-of-queries --iterations= --debug-info
Benchmark
Average number of seconds to run all queries: 0.201 seconds
Minimum number of seconds to run all queries: 0.098 seconds
Maximum number of seconds to run all queries: 0.595 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Average number of seconds to run all queries: 0.123 seconds
Minimum number of seconds to run all queries: 0.113 seconds
Maximum number of seconds to run all queries: 0.138 seconds
Number of clients running queries:
Average number of queries per client: User time 0.38, System time 0.27
Maximum resident set size , Integral resident set size
Non-physical pagefaults , Physical pagefaults , Swaps
Blocks in out , Messages in out , Signals
Voluntary context switches , Involuntary context switches
[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数据库的性能测试的更多相关文章
- MySQL/MariaDB数据库的Galera高可用性集群实战
MySQL/MariaDB数据库的Galera高可用性集群实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Galera Cluster概述 1>.什么是Gale ...
- MySQL/MariaDB数据库的MHA实现高可用实战
MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...
- MySQL/MariaDB数据库的PROXY实现读写分离
MySQL/MariaDB数据库的PROXY实现读写分离 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ProxySQL概述 1>.各家互联网公司读写分离的解决方案 m ...
- MySQL/MariaDB数据库的复制监控和维护
MySQL/MariaDB数据库的复制监控和维护 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.清理日志 1>.删除指定日志文件名称之前的日志(也可用基于时间) M ...
- MySQL/MariaDB数据库的复制加密
MySQL/MariaDB数据库的复制加密 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL的安全问题 1>.基于SSL复制 在默认的主从复制过程或远程连接 ...
- MySQL/MariaDB数据库的复制过滤器
MySQL/MariaDB数据库的复制过滤器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.复制过滤器概述 1>.复制器过滤器功能 让从节点仅复制指定的数据库,或指 ...
- MySQL/MariaDB数据库的半同步复制
MySQL/MariaDB数据库的半同步复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL半同步复制概述 1>.MySQL默认的异步复制 默认情况下,M ...
- MySQL/MariaDB数据库的主主复制
MySQL/MariaDB数据库的主主复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主主复制概述 1>.什么是主主复制 所谓的主主复制,说白了就是两台节点互为 ...
- MySQL/MariaDB数据库的主从级联复制
MySQL/MariaDB数据库的主从级联复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主从复制类型概述 1>.主从复制 博主推荐阅读: https://ww ...
随机推荐
- postman 测试Excel文件导入导出功能
1.导入的测试方法 选择form-data,key值填写方法对应的参数,选择File,Value处上传文件即可. 2. 导出的测试方法 在导出文件的时候,响应结果是乱码,然后在测试的时候选择下载,下载 ...
- python初级(302) 6 对象(四)
一.复习 1.什么是多态 2.复习上一节课内容 class Triangle: """ 三角形类 """ def __init__(self ...
- 第一次使用markdown
一级标题 二级标题 三家标题 四级标题 五级标题 六级标题 用两个空格来换行 斜体字 斜体字 加粗字体 加粗字体 斜体加粗字体 斜体加粗字体 无序列表用*或者+或者-: 第一箱 第二项 第三项 第四项 ...
- delimiter关键字
默认的sql语句以分号";"表示结束.mysql解释器每遇到一个分号,执行一段语句.可以通过delimiter更改语句结束符 mysql>delimiter &&am ...
- reentrant,thread-safe 和 async-signal-safe
可重入,线程安全和异步信号安全POSIX定义: Reentrant Function A function whose effect, when called by two or more threa ...
- net core 环境部署的坑
1.supervisor “no such file” error. 检查指令是否正确,路径.dotnet环境是否正常 2.Couldn‘t find a valid ICU package inst ...
- Android EditText禁止回车换行
在做一个登录页面的时候,发现了输入手机号的EditText可以输入回车的bug,影响用户体验,在此分享下解决办法. 百度了很多,都是设置singline=true的或者设置maxLines=" ...
- lvm的一些特殊命令
pvscan --cache # 将lvm信息同步到其他节点 ......未完待续
- Ubuntu下好用的pdf工具
安装okular sudo apt-get install okular 汉化 sudo apt-get install kde-l10n-zhcn 然后打开PDF文件时,右键选择打开方式选择okul ...
- [Linux] 在 Ubuntu 19.10 上开启 SSH 服务并允许远程登录
在 Ubuntu 19.10 上安装 SSH,并开启服务 0.检查并确认系统当前是否已安装SSH: sudo ps -e | grep ssh 如果只有 ssh-agent 说明 ssh-server ...