大家习惯于以响应时间来衡量性能表现,实际响应时间指的正是从接收请求开始到发送响应之间的时间跨度。我们通常的做法是在代码里加入日志计算时间,这个是不准确的,该方式只是单单计算应用程序内部经过的时间,没有计算网卡到应用程序,应用程序到网卡的时间。这个会由于系统的负载发生很大的变化!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%的结果。
安装部分:
下载地址: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 \n A newline character 95,99 Adds a prefix y A percentile indicator; see later in this section for more
例如: tcprstat -f '%n\n' -p 3306 -t 1 -n 0
语法为:
Shows version information.
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
tcprstat 还可以分析一个 TCPDUMP 抓包文件。
如果想将结果生成图像,可以利用gnuplot的图形,
具体参考:http://www.ibm.com/developerworks/cn/linux/l-gnuplot/?ca=dwcn-newsletter-linux