大家習慣于以響應時間來衡量性能表現,實際響應時間指的正是從接收請求開始到發送響應之間的時間跨度。我們通常的做法是在代碼裡加入日志計算時間,這個是不準确的,該方式隻是單單計算應用程式内部經過的時間,沒有計算網卡到應用程式,應用程式到網卡的時間。這個會由于系統的負載發生很大的變化!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 的計算方式:從最後的入站資料包的第一出站資料包鎖經過的時間。。僅包含tcp控制資訊的某些類型的資料包将被忽略。
百分比計算方式:對響應時間進行排序再取出N%的結果。
安裝部分:
該檔案是一個二進制檔案,需要 重命名、加上可執行權限。
執行:
輸出格式定義為:
Format Code
Header
Default?
Meaning
%n
count
y
Count of requests that completed during this iteration
%a
avg
Average response time
%s
sum
Sum of response times
%x
sqs
Sum of squares of response times
%m
min
Minimum response time
%M
max
Maximum response time
%h
med
Median response time
%S
stddev
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
Unix timestamp
%%
A literal %
\ t
A tab character
\n
A newline character
95,99
Adds a prefix
A percentile indicator; see later in this section for more
文法為:
Option Name
Short Name
Type
Default Value
Meaning
--format
-f
string
A format string; see above.
--[no]header
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
1
How many iterationstcprstat should execute before exiting; 0 means infinity.
--local
-l
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
Capture traffic only for the specified TCP port; if none, capture all traffic.
--read
-r
Read the specified pcap file instead of capturing traffic from the network.
--version
Shows version information.
tcprstat 還可以分析一個 TCPDUMP 抓封包件。
如果想将結果生成圖像,可以利用gnuplot的圖形,
本文轉自 位鵬飛 51CTO部落格,原文連結:http://blog.51cto.com/weipengfei/941918,如需轉載請自行聯系原作者