MySQL圧力テスト/sysbench使用
10995 ワード
今日はMySQL pxcクラスタの圧力測定を行いましたが、一般的にプロジェクトを行う際にDBAは業務に応じてデータベースの使用タイプをカスタマイズする必要がありますので、決定段階ではDBAは業務の見積りに基づいてデータベースクラスタのフィルタリングを行い、同時にデータベースを圧力測定します.
圧力測定の目的は、この機械がどのような条件下でデータベースの圧力が大きく、データベースがその機械のボトルネックがどこにあるかをテストすることである.言うまでもなく、私はそのデータベースよりもパフォーマンスが優れています.パフォーマンスとは、物理マシンが定義されている場合に最適なものを探しています.だから新しい物理機は理論的に新しいデータベースを選択してインストールする時すべて圧力測定を行います.MySQLは圧力測定ツールを持っていて、使いにくいと思います.現在主流のMySQL測定ツールsysbenchを使用しています.
ここでは、データベースの選択はビジネスに基づいて行われています.私のクラスタの性能が良いというわけではありません.私は彼を選択します.例えば、支払いシステムは、半同期性能がpxcよりいくら高くても、PXCのデータの強い一致性がなく、データの一致を保障することができます.だから、この時、半同期性能がもっと良いため、PXCを放棄することはできません.
ビジネス定義のデータベース・タイプをさらに設定すると、データベースをインストールして測定できます.主な手順は次のとおりです.
1.データベースをインストールし、ユーザーを新規作成して承認する.
2、sysbenchをインストールします.今回はcentos 7を使います.直接yumをインストールすればいいです.公式サイトにはインストールコマンドがあります.ネット上のバイナリコンパイルやyumコンパイルよりも頼りになります.だから、私もコマンドを書かないで、公式サイトに行ってみましょう.
3、sysbench実行命令を書いて圧測する
Sysbench圧力測定ツールの使用方法:
Sysbenchはバージョンによってコマンドが異なり、ネット上の他の人のコマンドを持ってノックしないでください.厳密な方法はsysbenchです.helpは現在のバージョンのコマンドフォーマットを表示します.私が使用しているバージョンのように.
sysbenchコマンドを使用する場合は、スクリプトファイルを実行する必要があります.yumがインストールされている場合、ほとんどは/usr/share/sysbenchフォルダの下にあります.例:
名前を見てもこれらのスクリプトだけで何をしているのか、insertは圧力測定挿入で、read圧力測定は読み取り専用で、read_writeは読み書きを測定し、7分程度で3分程度で書く割合ですが、通常は読み書きスクリプトを使えばいいのですが、読み書きが分離されたライブラリで読み取り専用または書き込み専用であれば、単独で読み書きと書き込みを測定することができます
起動パラメータ、圧力測定方式スクリプト、起動コマンドがあれば、圧力測定を開始します.今回の圧力測定コマンドは:
そこで、一般的に使用するパラメータは、新規データベース、ユーザーおよびそのパスワード、レポート時間(10秒に1回)、実行圧力測定時間(120秒)、圧力測定テーブル数(4枚)、テーブルデータ量(1千万)、スレッド(1)、実行圧力測定方式スクリプト(読み書き)、最後に準備コマンド(prepare)を加えることです.
ここでsysbench[options]...[testname][command]ここのcommandは、
commandコマンドにはprepare、run、cleanupの3つがあります.
それぞれに対応するのは、テーブルとそのデータを準備し、圧力測定を実行し、データを整理することです.データベースにライブラリを新規作成しただけでテーブルが新規に作成されていないため、パラメータがテーブルのプロパティを指定するときはsysbenchが自分で新規作成し、指定したプロパティを完了するので、圧力測定前にprepareコマンドを実行します.
準備が完了したら、次の操作を行います.
runコマンドでは、圧力測定を行います.この場合、関連する圧力測定データは10秒おきに出力されます.
最後にcleanupパージ結果を実行します.
圧力測定方式では、デフォルトで新しく作成されたテーブルは4つのフィールド程度で、4枚のテーブル、100000万のデータレベルを定義しました.圧力測定のこれらの属性は変わらず、その後、スレッドは1から始まり、1、5、10、20、50、100、200、500、1000のグループでテストを行い、できるだけ性能の減衰点を見つけます.スレッドが減衰点を見つけた後、テーブルの数、テーブルのサイズなどをゆっくり調整してみて、別のパラメータを交換するにはprepareが必要です.このマシン上のデータベースのパフォーマンスのボトルネックを把握することは、後期DBAデータベースのメンテナンスに役立ちます.
例えば、私は今回スレッドを開いて結果を報告しました.
圧力測定の目的は、この機械がどのような条件下でデータベースの圧力が大きく、データベースがその機械のボトルネックがどこにあるかをテストすることである.言うまでもなく、私はそのデータベースよりもパフォーマンスが優れています.パフォーマンスとは、物理マシンが定義されている場合に最適なものを探しています.だから新しい物理機は理論的に新しいデータベースを選択してインストールする時すべて圧力測定を行います.MySQLは圧力測定ツールを持っていて、使いにくいと思います.現在主流のMySQL測定ツールsysbenchを使用しています.
ここでは、データベースの選択はビジネスに基づいて行われています.私のクラスタの性能が良いというわけではありません.私は彼を選択します.例えば、支払いシステムは、半同期性能がpxcよりいくら高くても、PXCのデータの強い一致性がなく、データの一致を保障することができます.だから、この時、半同期性能がもっと良いため、PXCを放棄することはできません.
ビジネス定義のデータベース・タイプをさらに設定すると、データベースをインストールして測定できます.主な手順は次のとおりです.
1.データベースをインストールし、ユーザーを新規作成して承認する.
2、sysbenchをインストールします.今回はcentos 7を使います.直接yumをインストールすればいいです.公式サイトにはインストールコマンドがあります.ネット上のバイナリコンパイルやyumコンパイルよりも頼りになります.だから、私もコマンドを書かないで、公式サイトに行ってみましょう.
3、sysbench実行命令を書いて圧測する
Sysbench圧力測定ツールの使用方法:
Sysbenchはバージョンによってコマンドが異なり、ネット上の他の人のコマンドを持ってノックしないでください.厳密な方法はsysbenchです.helpは現在のバージョンのコマンドフォーマットを表示します.私が使用しているバージョンのように.
[root@d8555732f478 sysbench]# sysbench testname --help
Usage:
sysbench [options]... [testname] [command]
Commands implemented by most tests: prepare run cleanup help
General options:
--threads=N number of threads to use [1]
--events=N limit for total number of events [0]
--time=N limit for total execution time in seconds [10]
--forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]
--thread-stack-size=SIZE size of stack per thread [64K]
--rate=N average transactions rate. 0 for unlimited rate [0]
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
--report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
--debug[=on|off] print more debugging info [off]
--validate[=on|off] perform validation checks where possible [off]
--help[=on|off] print help and exit [off]
--version[=on|off] print version and exit [off]
--config-file=FILENAME File containing command line options
--tx-rate=N deprecated alias for --rate [0]
--max-requests=N deprecated alias for --events [0]
--max-time=N deprecated alias for --time [0]
--num-threads=N deprecated alias for --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 specifies database driver to use ('help' to get list of available drivers) [mysql]
--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 - MySQL driver
pgsql - PostgreSQL driver
mysql options:
--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:
--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 help' for a list of options for each test.
sysbenchコマンドを使用する場合は、スクリプトファイルを実行する必要があります.yumがインストールされている場合、ほとんどは/usr/share/sysbenchフォルダの下にあります.例:
[root@d8555732f478 sysbench]# ls
bulk_insert.lua oltp_delete.lua oltp_point_select.lua oltp_read_write.lua oltp_update_non_index.lua select_random_points.lua tests
oltp_common.lua oltp_insert.lua oltp_read_only.lua oltp_update_index.lua oltp_write_only.lua select_random_ranges.lua
[root@d8555732f478 sysbench]# pwd
/usr/share/sysbench
名前を見てもこれらのスクリプトだけで何をしているのか、insertは圧力測定挿入で、read圧力測定は読み取り専用で、read_writeは読み書きを測定し、7分程度で3分程度で書く割合ですが、通常は読み書きスクリプトを使えばいいのですが、読み書きが分離されたライブラリで読み取り専用または書き込み専用であれば、単独で読み書きと書き込みを測定することができます
起動パラメータ、圧力測定方式スクリプト、起動コマンドがあれば、圧力測定を開始します.今回の圧力測定コマンドは:
sysbench --mysql-host=45.59.111.111 --mysql-port=33061 --mysql-user=testuser --mysql-password=123456 \
--mysql-db=testdb --report-interval=10 --time=120 --tables=4 --table-size=10000000 --threads=1 \
/usr/share/sysbench/oltp_read_write.lua prepare
そこで、一般的に使用するパラメータは、新規データベース、ユーザーおよびそのパスワード、レポート時間(10秒に1回)、実行圧力測定時間(120秒)、圧力測定テーブル数(4枚)、テーブルデータ量(1千万)、スレッド(1)、実行圧力測定方式スクリプト(読み書き)、最後に準備コマンド(prepare)を加えることです.
ここでsysbench[options]...[testname][command]ここのcommandは、
commandコマンドにはprepare、run、cleanupの3つがあります.
それぞれに対応するのは、テーブルとそのデータを準備し、圧力測定を実行し、データを整理することです.データベースにライブラリを新規作成しただけでテーブルが新規に作成されていないため、パラメータがテーブルのプロパティを指定するときはsysbenchが自分で新規作成し、指定したプロパティを完了するので、圧力測定前にprepareコマンドを実行します.
準備が完了したら、次の操作を行います.
sysbench --mysql-host=45.59.113.211 --mysql-port=33061 --mysql-user=testuser --mysql-password=123456 \
--mysql-db=testdb --report-interval=10 --time=120 --tables=4 --table-size=10000000 --threads=1 \
/usr/share/sysbench/oltp_read_write.lua run
runコマンドでは、圧力測定を行います.この場合、関連する圧力測定データは10秒おきに出力されます.
最後にcleanupパージ結果を実行します.
sysbench --mysql-host=45.59.113.211 --mysql-port=33061 --mysql-user=testuser --mysql-password=123456 \
--mysql-db=testdb --report-interval=10 --time=120 --tables=4 --table-size=10000000 --threads=1 \
/usr/share/sysbench/oltp_read_write.lua cleanup
圧力測定方式では、デフォルトで新しく作成されたテーブルは4つのフィールド程度で、4枚のテーブル、100000万のデータレベルを定義しました.圧力測定のこれらの属性は変わらず、その後、スレッドは1から始まり、1、5、10、20、50、100、200、500、1000のグループでテストを行い、できるだけ性能の減衰点を見つけます.スレッドが減衰点を見つけた後、テーブルの数、テーブルのサイズなどをゆっくり調整してみて、別のパラメータを交換するにはprepareが必要です.このマシン上のデータベースのパフォーマンスのボトルネックを把握することは、後期DBAデータベースのメンテナンスに役立ちます.
例えば、私は今回スレッドを開いて結果を報告しました.
[root@d8555732f478 sysbench]# sysbench --mysql-host=45.59.111.111 --mysql-port=33061 --mysql-user=testuser --mysql-password=123456 \
> --mysql-db=testdb --report-interval=10 --time=120 --tables=4 --table-size=10000000 --threads=1 \
> /usr/share/sysbench/oltp_read_write.lua run
sysbench 1.0.17 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 10s ] thds: 1 tps: 12.06 qps: 242.03 (r/w/o: 169.56/23.33/49.14) lat (ms,95%): 147.61 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 18.15 qps: 363.61 (r/w/o: 254.74/37.80/71.08) lat (ms,95%): 108.68 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 1 tps: 18.09 qps: 361.11 (r/w/o: 252.57/37.18/71.36) lat (ms,95%): 130.13 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 1 tps: 23.92 qps: 478.01 (r/w/o: 334.49/47.54/95.98) lat (ms,95%): 90.78 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 1 tps: 21.30 qps: 426.56 (r/w/o: 298.77/42.30/85.49) lat (ms,95%): 97.55 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 1 tps: 25.00 qps: 499.74 (r/w/o: 349.73/51.10/98.91) lat (ms,95%): 81.48 err/s: 0.00 reconn/s: 0.00
[ 70s ] thds: 1 tps: 23.70 qps: 474.82 (r/w/o: 332.61/45.20/97.00) lat (ms,95%): 87.56 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 1 tps: 24.20 qps: 484.30 (r/w/o: 338.80/48.90/96.60) lat (ms,95%): 89.16 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 1 tps: 24.30 qps: 484.18 (r/w/o: 338.79/47.70/97.70) lat (ms,95%): 90.78 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 1 tps: 25.20 qps: 505.81 (r/w/o: 354.21/49.40/102.20) lat (ms,95%): 84.47 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 1 tps: 29.00 qps: 578.40 (r/w/o: 404.70/58.30/115.40) lat (ms,95%): 69.29 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: 1 tps: 29.70 qps: 594.91 (r/w/o: 416.71/58.10/120.10) lat (ms,95%): 68.05 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 38458
write: 5469
other: 11013
total: 54940
transactions: 2747 (22.88 per sec.) --TPS
queries: 54940 (457.68 per sec.) --QPS
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 120.0385s
total number of events: 2747
Latency (ms):
min: 7.22
avg: 43.68
max: 857.01
95th percentile: 94.10
sum: 119989.56
Threads fairness:
events (avg/stddev): 2747.0000/0.00
execution time (avg/stddev): 119.9896/0.00