MySQL応答時間モニタリング


応答時間で性能表現を測定することに慣れており、実際の応答時間とは、受信要求から送信応答までの時間スパンを指す.私たちの通常の方法は、コードにログ計算時間を追加することです.これは正確ではありません.この方法は、アプリケーション内部の経過時間だけを計算し、NICからアプリケーション、アプリケーションからNICまでの時間を計算しません.これはシステムの負荷によって大きく変化します!Wiresharkとtcpdumpのようなバッグをつかむ方法は、持続的ではないことを忍耐する必要があります.
今日はPercona社のオープンソースのツール:Tcprstatです.
概要:Tcprstatは無料で、オープンソースのTCP分析ツールで、ネットワークの伝送を検出し、要求と応答の間のdelayを計算します.その出力フォーマットはlinuxのvmstat iostatのフォーマットのように出力されます.このツールは、あるポートのトラフィックを検出できます.だからmysqld httpd memcachedのような単一のデーモンプロセスの要求と応答時間、または他のprocesserを傍受することができます.(PS:このツールはMySQLだけではありませんよ)
メリット:
1、軽量級、コストが少なく、大量のログを書き込む必要がなく、大量のログを分析する必要がない
2、要求と応答の時間は微妙なレベルに正確である.
3、出力された情報を簡単に表にインポートしたり、スクリプトでフォーマットしたり、gnuplotのグラフィックを使用したりします.
4、これはプロトコルに関係なく、works well for a large variety of client-server protocols that have a simple request-response model
5、Tcprstatはresponseの時間計算に注目し、ネットカード流量の計算ではない
Response timesの計算方式:最後のインバウンドパケットの第1アウトバウンドパケットロックから経過した時間.tcp制御情報のみを含むいくつかのタイプのパケットは無視されます.
パーセンテージ計算方式:応答時間を並べ替えてN%の結果を取り出す.
インストール:
ダウンロードアドレス:statically linked 64-bit binary(version 0.3.1)
このファイルはバイナリファイルで、名前を変更し、実行可能な権限を追加する必要があります.
実行:

     ./tcprstat -p 3306 -t 2 -n 2
     timestamp count max  min avg med stddev 95_max 95_avg 95_std 99_max  99_avg  99_std
     1343190264      72      2380    108     289     209     285     547     237     95      909     259     143

出力フォーマットは次のように定義されます.
             Format Code     
    Header
  Default?   
 Meaning
  %n
count
y
Count of requests that completed during this iteration
  %a
avg
y
Average response time
  %s
sum
y
Sum of response times
  %x
sqs
 
Sum of squares of response times
  %m
min
y
Minimum response time
  %M
max
y
Maximum response time
  %h
med
y
Median response time
  %S
stddev
y
Standard deviation of response times
  %v
var
 
Variance of response times
 %I
iter#
 
Iteration number
 %t
elapsed
 
Seconds elapsed since the first iteration
 %T
timestamp
y
Unix timestamp
 %%
 
 
A literal %
\t
 
 
A tab character
 
 
A newline character
95,99
Adds a prefix
y
A percentile indicator; see later in this section for more
 tcprstat -f '%n
' -p 3306 -t 1 -n 0

 
構文:
Option Name
Short Name
Type
Default Value
Meaning
--format
-f
string
 
A format string; see above.
--[no]header
 
string
Enabled
If no argument is given, tcprstat auto-generates the header based on --format. If an argument is given,tcprstat uses that as the header instead. If --no-header is used,tcprstat will not print a header.
--help
 
 
 
Shows program information and usage.
--interval
-t
integer
10
The number of seconds tcprstatwaits between each successive line of output.
--iterations
-n
integer
1
How many iterationstcprstat should execute before exiting; 0 means infinity.
--local
-l
string
 
Accepts a comma-separated list of IP addresses to consider as local IP addresses, instead of getting a list from the operating system.
--port
-p
integer
 
Capture traffic only for the specified TCP port; if none, capture all traffic.
--read
-r
string
 
Read the specified pcap file instead of capturing traffic from the network.
--version
 
 
 
Shows version information.
tcprstatはまた、TCPDUMPパケットファイルを分析することもできる.
結果を画像に生成するにはgnuplotのグラフィックを利用して、
具体的な参考:http://www.ibm.com/developerworks/cn/linux/l-gnuplot/?ca=dwcn-newsletter-linux
参考資料:http://www.percona.com/docs/wiki/tcprstat:start