A、MySQLはストレステストツールが付属しています--Mysqlslap
mysqlslapはは、構文は柔軟で使いやすい、シンプルでクエリデータというMySQLの独自のベンチマークツールです。ツールは、同時に複数のクライアントをシミュレートし、サーバーのアップデートにクエリを発行することができ、性能試験データを与えられ、さまざまなを提供しますエンジンの性能を比較します。検証のための直感的な基礎を提供するために、MySQLのパフォーマンスの最適化のmysqlslapの前と後に、システムの運用・保守およびDBAスタッフが正確なデータベースサポートなどのストレスの問題にオンラインユーザトラフィックと制限抵抗を把握するために、いくつかの一般的なストレステストツールを持っている必要があります。
1、接続のデフォルトの最大数を変更
MySQLの圧力試験の前に、我々は次のように、接続のデフォルトの最大数を変更する必要があります。
[root@mysql data]# vim /etc/my.cnf #编辑主配置文件
[mysqld]
............#省略部分内容
max_connections=1024
次のとおりです。
mysql> show variables like 'max_connections'; #查看最大连接数
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1024 |
+-----------------+-------+
1 row in set (0.00 sec)
ストレステスト:
[root@mysql ~]# mysqlslap --defaults-file=/etc/my.cnf --concurrency=100,200 --iterations=1 --number-int-cols=20 --number-char-cols=30 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam,innodb --number-of-queries=2000 -uroot -p123.com --verbose
コマンド上記試験の説明:アナログテスト2つの同時読み取りおよび書き込み、第100、第200は、自動的にSQLスクリプトを生成し、初期化テストテーブル20は、フィールド30の含有
各クエリ要求実行チャーSフィールド2000。テストエンジンはMyISAMテーブル、InnoDBのです。(これらのオプションの多くは、各オプションの説明を理解したいならば、あなたはmysqlslapは--helpクエリを使用することができ、デフォルトの値を省略することができますされているがあります)
上記のコマンドは、次の結果を返します。
試験結果は:同時に0.557 / Sによって調査とMYISAM最初のクライアント100を開始し、0.256によって0.522 / sのINNODB最初のクライアント100を開始探索によって、第2のクライアント200を開始検索は/同時にだが、クライアント200第2のルックアップは、0.303 / sのによって開始されている間。
実際のニーズ、同時テストの数を増加させるための圧力を少しによります。
第二に、ストレステストsysbenchにサードパーティ製ツールの使用
1、インストールツールのsysbench
[root@mysql ~]# yum -y install epel-release #安装第三方epel源
[root@mysql ~]# yum -y install sysbench #安装sysbench工具
[root@mysql ~]# sysbench --version #确定工具已安装
sysbench 1.0.17
sysbenchは、次のテストを実行することができます。
- CPUの演算性能試験
- ディスクIO性能試験
- スケジューラの性能試験
- メモリ割り当て及び伝送速度試験
- POSIXスレッドの性能試験
- データベースの性能試験(スクリプトが実行oltp_read_only.lua例えばOLTPベンチマーク、必要性のLuaスクリプトの実行を/ usr / share / sysbench /ディレクトリには、読み取り専用テスト)
- あなたはsysbenchは、コマンドを実行することができたときに、テストをカスタマイズするために、独自のLuaスクリプトを指定します。
2は、sysbenchツールのヘルプオプションを表示します
[root@mysql ~]# sysbench --help
Usage:
sysbench [options]... [testname] [command]
Commands implemented by most tests: prepare run cleanup help # 可用的命令,四个
General options: # 通用选项
--threads=N 要使用的线程数,默认 1 个 [1]
--events=N 最大允许的事件个数 [0]
--time=N 最大的总执行时间,以秒为单位 [10]
--forced-shutdown=STRING 在 --time 时间限制到达后,强制关闭之前等待的秒数,默认“off”禁用(number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable) [off]
--thread-stack-size=SIZE 每个线程的堆栈大小 [64K]
--rate=N 平均传输速率。0 则无限制 [0]
--report-interval=N 以秒为单位定期报告具有指定间隔的中间统计信息 0 禁用中间报告 [0]
--report-checkpoints=[LIST,...] 转储完整的统计信息并在指定的时间点重置所有计数器。参数是一个逗号分隔的值列表,表示从测试开始经过这个时间量时必须执行报告检查点(以秒为单位)。报告检查点默认关闭。 []
--debug[=on|off] 打印更多 debug 信息 [off]
--validate[=on|off] 尽可能执行验证检查 [off]
--help[=on|off] 显示帮助信息并退出 [off]
--version[=on|off] 显示版本信息并退出 [off]
--config-file=FILENAME 包含命令行选项的文件
--tx-rate=N 废弃,改用 --rate [0]
--max-requests=N 废弃,改用 --events [0]
--max-time=N 废弃,改用 --time [0]
--num-threads=N 废弃,改用 --threads [1]
Pseudo-Random Numbers Generator options: # 伪随机数发生器选项
--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
--rand-spec-iter=N number of iterations used for numbers generation [12]
--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
--rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
--rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0]
--rand-pareto-h=N parameter h for pareto distribution [0.2]
Log options: # 日志选项
--verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
--percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]
--histogram[=on|off] print latency histogram in report [off]
General database options: # 通用的数据库选项
--db-driver=STRING 指定要使用的数据库驱动程序 ('help' to get list of available drivers)
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
--db-debug[=on|off] print database-specific debug information [off]
Compiled-in database drivers: # 內建的数据库驱动程序,默认支持 MySQL 和 PostgreSQL
mysql - MySQL driver
pgsql - PostgreSQL driver
mysql options: # MySQL 数据库专用选项
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=[LIST,...] MySQL server port [3306]
--mysql-socket=[LIST,...] MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-ssl[=on|off] use SSL connections, if available in the client library [off]
--mysql-ssl-cipher=STRING use specific cipher for SSL connections []
--mysql-compression[=on|off] use compression, if available in the client library [off]
--mysql-debug[=on|off] trace all client library calls [off]
--mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]
--mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]
pgsql options: # PostgreSQL 数据库专用选项
--pgsql-host=STRING PostgreSQL server host [localhost]
--pgsql-port=N PostgreSQL server port [5432]
--pgsql-user=STRING PostgreSQL user [sbtest]
--pgsql-password=STRING PostgreSQL password []
--pgsql-db=STRING PostgreSQL database name [sbtest]
Compiled-in tests: # 內建测试类型
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
See 'sysbench <testname> help' for a list of options for each test.
3、sysbenchテストMySQLデータベースのパフォーマンス
1)試験データの準備
#查看sysbench自带的lua脚本使用方法
[root@mysql ~]# sysbench /usr/share/sysbench/oltp_common.lua help
#必须创建sbtest库,sbtest事sysbench默认使用的库名
[root@mysql ~]# mysqladmin -uroot -p123.com create sbtest;
#然后,准备测试所用的表,这些测试表放在测试库sbtest中。这里使用的lua脚本为/usr/share/sysbench/oltp_common.lua。
[root@mysql ~]# sysbench --mysql-host=127.0.0.1 \
> --mysql-port=3306 \
> --mysql-user=root \
> --mysql-password=123.com \
> /usr/share/sysbench/oltp_common.lua \
> --tables=10 \
> --table_size=100000 \
> prepare
#其中--tables=10表示创建10个测试表,
#--table_size=100000表示每个表中插入10W行数据,
#prepare表示这是准备数的过程。
2)試験データの存在を確認します
[root@mysql ~]# mysql -uroot -p123.com sbtest; #登录到sbtest库
mysql> show tables; #查看相应的表
+------------------+
| Tables_in_sbtest |
+------------------+
| sbtest1 |
| sbtest10 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+------------------+
10 rows in set (0.00 sec)
mysql> select count(*) from sbtest1; #随机选择一个表,确认其有100000条数据
+----------+
| count(*) |
+----------+
| 100000 |
+----------+
1 row in set (0.01 sec)
3)データベースのテストおよび結果分析
これをテストするために使用することができる前に、文は、わずかに修正されたデータで調製しました。
oltp_common.luaのためのluaスクリプトを使用する前に、それを直接テストに使用することはできない、汎用的なスクリプトは、他のLUAスクリプトを起動されている、ことに注意してください。
だから、私はoltp_read_write.luaは、スクリプト、筆記試験を読んで行うためにここにいます。このよう読み取り専用のテスト、書き込み専用のテストなどのテストの多くの他のタイプは、テストなどの挿入テスト、ハイボリュームを削除し、あります。あなたは、対応するLuaのスクリプトを呼び出すことができます見つけることができます。
#执行测试命令如下:
[root@mysql ~]# sysbench --threads=4 \
> --time=20 \
> --report-interval=5 \
> --mysql-host=127.0.0.1 \
> --mysql-port=3306 \
> --mysql-user=root \
> --mysql-password=123.com \
> /usr/share/sysbench/oltp_read_write.lua \
> --tables=10 \
> --table_size=100000 \
> run
次のようにコマンドの結果が返されます。
[root@mysql ~]# sysbench --threads=4 --time=20 --report-interval=5 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123.com /usr/share/sysbench/oltp_read_write.lua --tables=10 --table_size=100000 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 4
Report intermediate results every 5 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
#以下是每5秒返回一次的结果,统计的指标包括:
# 线程数、tps(每秒事务数)、qps(每秒查询数)、
# 每秒的读/写/其它次数、延迟、每秒错误数、每秒重连次数
[ 5s ] thds: 4 tps: 675.29 qps: 13513.94 (r/w/o: 9460.62/2701.95/1351.37) lat (ms,95%): 8.58 err/s: 0.00 reconn/s: 0.00
[ 10s ] thds: 4 tps: 679.05 qps: 13586.79 (r/w/o: 9511.29/2717.40/1358.10) lat (ms,95%): 8.58 err/s: 0.00 reconn/s: 0.00
[ 15s ] thds: 4 tps: 676.82 qps: 13538.23 (r/w/o: 9476.70/2707.69/1353.84) lat (ms,95%): 8.74 err/s: 0.20 reconn/s: 0.00
[ 20s ] thds: 4 tps: 684.62 qps: 13692.11 (r/w/o: 9585.02/2737.86/1369.23) lat (ms,95%): 8.43 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 190190 # 执行的读操作数量
write: 54337 # 执行的写操作数量
other: 27169 # 执行的其它操作数量
total: 271696
transactions: 13584 (678.88 per sec.) # 执行事务的平均速率
queries: 271696 (13578.35 per sec.) # 平均每秒能执行多少次查询
ignored errors: 1 (0.05 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 20.0084s # 总消耗时间
total number of events: 13584 # 总请求数量(读、写、其它)
Latency (ms):
min: 2.68
avg: 5.89
max: 38.21
95th percentile: 8.58 # 采样计算的平均延迟
sum: 79985.65
Threads fairness:
events (avg/stddev): 3396.0000/60.84
execution time (avg/stddev): 19.9964/0.00
図4に示すように、CPU / IO /テストメモリなど
次のようにsysbench構築され、いくつかのテストの指標は以下のとおりです。
[root@mysql ~]# sysbench --help
.......... # 省略部分内容
Compiled-in tests:
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
ヘルプダイレクト出力試験方法、例えば、FILEIOテスト:
[root@mysql ~]# sysbench fileio help
sysbench 1.0.17 (using system LuaJIT 2.0.4)
fileio options:
--file-num=N number of files to create [128]
--file-block-size=N block size to use in all IO operations [16384]
--file-total-size=SIZE total size of files to create [2G]
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]
--file-async-backlog=N number of asynchronous operatons to queue per thread [128]
--file-extra-flags=[LIST,...] list of additional flags to use to open files {sync,dsync,direct} []
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]
--file-fsync-all[=on|off] do fsync() after each write operation [off]
--file-fsync-end[=on|off] do fsync() at the end of test [on]
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
--file-rw-ratio=N reads/writes ratio for combined test [1.5]
1)試験IOパフォーマンス
たとえば、5つのファイル、2Gの合計を作成し、各ファイルは、おそらく400Mです。
[root@mysql ~]# sysbench fileio --file-num=5 --file-total-size=2G prepare
[root@mysql ~]# ll -lh test*
-rw------- 1 root root 410M 1月 2 18:47 test_file.0
-rw------- 1 root root 410M 1月 2 18:47 test_file.1
-rw------- 1 root root 410M 1月 2 18:48 test_file.2
-rw------- 1 root root 410M 1月 2 18:48 test_file.3
-rw------- 1 root root 410M 1月 2 18:48 test_file.4
その後、テストを実行します。
[root@mysql ~]# sysbench --events=5000 \
> --threads=16 \
> fileio \
> --file-num=5 \
> --file-total-size=2G \
> --file-test-mode=rndrw \
> --file-fsync-freq=0 \
> --file-block-size=16384 \
> run
次のように返された結果は以下のとおりです。
Initializing worker threads...
Threads started!
File operations:
reads/s: 6374.88
writes/s: 4271.21
fsyncs/s: 170.34
Throughput: #吞吐量
read, MiB/s: 99.61 #表示读带宽
written, MiB/s: 66.74 #表示写的带宽
General statistics:
total time: 0.4684s
total number of events: 5000
Latency (ms):
min: 0.00
avg: 0.99
max: 50.64
95th percentile: 4.74
sum: 4940.23
Threads fairness:
events (avg/stddev): 312.5000/15.32
execution time (avg/stddev): 0.3088/0.01
2)試験CPU性能
[root@mysql ~]# sysbench cpu --threads=40 --events=10000 --cpu-max-prime=20000 run
--------この記事の最後に、これまで、読んでくれてありがとう--------