??xml version="1.0" encoding="utf-8" standalone="yes"?>
要戳破这个错误结? 可以从理论和实践两方面来.
pȝ通过一个四元组来唯一标识一条TCPq接. q个四元l的l构是{local ip, local port, remote ip, remote port}, 对于IPv4, pȝ理论上最多可以管?^(32+16+32+16), 2?6ơ方个连? 如果不仅仅考虑TCP, 则是一个五元组, 加上协议?TCP, UDP或者其?.
服务器绑定一个ip:port, 然后acceptq接, 所有accept的连接用的本地地址也是同样的ip:port.
如果某个客户端向同一个TCP端点(ip:port)发vdq接, 那么每一条连接都必须使用不同的本地TCP端点, 如果客户端只有一个IP则是使用不同的本地端? 该端口的范围?nixpȝ上的一个例子是32768?1000, 可以通过如下命o查看:
[root@benegg.com ~]# cat /proc/sys/net/ipv4/ip_local_port_range 32768 61000
也就是说, 一个客Lq接同一个服务器(比如q行压力试), 最多可以发?0000个左右的q接.
TCP客户?TCP的主动发赯?可以在同一ip:port上向不同的服务器发vdq接, 只需在bind之前对socket讄SO_REUSEADDR选项.
pȝ支持的最大打开文g描述W数(包括socketq接):
[root@benegg.com ~]# cat /proc/sys/fs/file-max 580382
单个q程所能打开的最大文件描q符?
[root@benegg.com ~]# ulimit -n 1024
无论是对于服务器q是客户? 认ؓ”一台机器最多徏?5536个TCPq接”是没有根据的, 理论上远q超q这个?
一、http_load
E序非常,解压后也不到100K
http_load以ƈ行复用的方式q行Q用以测试web服务器的吞吐量与负蝲。但是它不同于大多数压力试?/p>
P它可以以一个单一的进E运行,一般不会把客户机搞歅R还可以试HTTPScȝ|站h?/p>
下蝲地址Q?a style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">http://soft.vpser.net/test/http_load/http_load-12mar2006.tar.gz
安装很简?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> #tar zxvf http_load-12mar2006.tar.gz
#cd http_load-12mar2006
#make && make install
命o格式Qhttp_load -p q发讉Kq程?nbsp; -s 讉K旉 需要访问的URL文g
参数其实可以自由l合Q参C间的选择q没有什么限制。比如你写成http_load -parallel 5 -seconds
300 urls.txt也是可以的。我们把参数l大家简单说明一下?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> -parallel ?p Q含义是q发的用戯E数?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> -fetches ?f Q含义是总计的访问次?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> -rate ?p Q含义是每秒的访问频?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> -seconds?s Q含义是总计的访问时?/p>
准备URL文gQurllist.txtQ文件格式是每行一个URLQURL最好超q?0Q?00个测试效果比较好.文g格式
如下Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> http://www.vpser.net/uncategorized/choose-vps.html
http://www.vpser.net/vps-cp/hypervm-tutorial.html
http://www.vpser.net/coupons/diavps-april-coupons.html
http://www.vpser.net/security/vps-backup-web-mysql.html
例如Q?/p>
http_load -p 30 -s 60 urllist.txt
参数了解了,我们来看q行一条命令来看看它的q回l果
命oQ? ./http_load -rate 5 -seconds 10 urls说明执行了一个持l时?0U的试Q每U的频率??/p>
49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds5916 mean bytes/connection4.89274
fetches/sec, 28945.5 bytes/secmsecs/connect: 28.8932 mean, 44.243 max, 24.488 minmsecs/first
-response: 63.5362 mean, 81.624 max, 57.803 minHTTP response codes: code 200 — 49
l果分析Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 1Q?9 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
说明在上面的试中运行了49个请求,最大的q发q程数是2Q总计传输的数据是289884bytesQ运行的旉?0.0148U?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 2Q?916 mean bytes/connection说明每一q接q_传输的数据量289884/49=5916
3Q?.89274 fetches/sec, 28945.5 bytes/sec
说明每秒的响应请求ؓ4.89274Q每U传递的数据?8945.5 bytes/sec
4Qmsecs/connect: 28.8932 mean, 44.243 max, 24.488 min说明每连接的q_响应旉?8.8932 msecs
Q最大的响应旉44.243 msecsQ最的响应旉24.488 msecs
5Qmsecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
6、HTTP response codes: code 200 — 49 说明打开响应面的类型,如果403的类型过多,那可?/p>
要注意是否系l遇C瓉?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> Ҏ说明Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 试l果中主要的指标?fetches/sec、msecs/connect q个选项Q即服务器每U能够响应的查询ơ数Q?/p>
用这个指标来衡量性能。似乎比 apache的ab准确率要高一些,也更有说服力一些?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> Qpt-每秒响应用户数和response timeQ每q接响应用户旉?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 试的结果主要也是看q两个倹{当然仅有这两个指标q不能完成对性能的分析,我们q需要对服务器的
cpu、menq行分析Q才能得出结?/p>
二、webbench
webbench是Linux下的一个网站压力测试工P最多可以模?万个q发q接L试网站的负蝲能力。下载地址可以到google搜,我这里给Z?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 下蝲地址Q?a style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">http://soft.vpser.net/test/webbench/webbench-1.5.tar.gz
q个E序更小Q解压后不到50KQ呵?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 安装非常?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> #tar zxvf webbench-1.5.tar.gz
#cd webbench-1.5
#make && make install
会在当前目录生成webbench可执行文Ӟ直接可以使用?/p>
用法Q?/p>
webbench -c q发?-t q行试旉 URL
如:
webbench -c 5000 -t 120 http://www.vpser.net
三、ab
ab是apache自带的一Ƒ֊能强大的试工具
安装了apache一般就自带了,
用法可以查看它的说明
$ ./ab
./ab: wrong number of arguments
Usage: ./ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-p postfile File containing data to POST
-T content-type Content-type header for POSTing
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. ‘Apache=1234. (repeatable)
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
参数众多Q一般我们用到的?n ?c
例如Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> ./ab -c 1000 -n 100 http://www.vpser.net/index.php
q个表示同时处理1000个请求ƈq行100ơindex.php文g.
四、Siege
一Ƒּ源的压力试工具Q可以根据配|对一个WEB站点q行多用Lq发讉KQ记录每个用h有请求过E的相应旉Qƈ在一定数量的q发讉K下重复进行?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> 官方Q?a style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">http://www.joedog.org/
Siege下蝲Q?a style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #3e62a6; outline-width: 0px; outline-style: initial; outline-color: initial; ">http://soft.vpser.net/test/siege/siege-2.67.tar.gz
解压Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> # tar -zxf siege-2.67.tar.gz
q入解压目录Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> # cd siege-2.67/
安装Q?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> #./configure ; make
#make install
使用
siege -c 200 -r 10 -f example.url
-c是ƈ发量Q?r是重复次数?url文g是一个文本,每行都是一个urlQ它会从里面随机讉K的?/p>
example.url内容:
http://www.licess.cn
http://www.vpser.net
http://soft.vpser.net
l果说明
Lifting the server siege… done.
Transactions: 3419263 hits //完成419263ơ处?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> Availability: 100.00 % //100.00 % 成功?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> Elapsed time: 5999.69 secs //d用时
Data transferred: 84273.91 MB //共数据传?4273.91 MB
Response time: 0.37 secs //相应用时1.65U:昄|络q接的速度
Transaction rate: 569.91 trans/sec //均每U完?569.91 ơ处理:表示服务器后
Throughput: 14.05 MB/sec //q_每秒传送数?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> Concurrency: 213.42 //实际最高ƈ发数
Successful transactions: 2564081 //成功处理ơ数
Failed transactions: 11 //p|处理ơ数
Longest transaction: 29.04 //每次传输所花最长时?br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /> Shortest transaction: 0.00 //每次传输所花最短时?/p>