linux--apache的ab命令

1.最基本的关心两个选项-c-n

例:./ab-c100-n10000http://127.0.0.1/index.php

-c100即:每次并发100个

-n10000即:共发送10000个请求

2.测试结果分析

[junjie2@loginhtdocs]$/data1/apache/bin/ab-c1000-n50000"http://10.10.10.10/a.php"

ThisisApacheBench,Version1.3d<$Revision:1.73$>apache-1.3

Copyright(c)1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/

Copyright(c)1998-2002TheApacheSoftwareFoundation,http://www.apache.org/

Benchmarking10.65.129.21(bepatient)

Completed5000requests

Completed10000requests

Completed15000requests

Completed20000requests

Completed25000requests

Completed30000requests

Completed35000requests

Completed40000requests

Completed45000requests

Finished50000requests

ServerSoftware:Apache/1.3.33

ServerHostname:10.65.129.21

ServerPort:80

DocumentPath:/a.php//请求的资源

DocumentLength:0bytes//文档返回的长度,不包括相应头

ConcurrencyLevel:1000//并发个数

Timetakenfortests:48.650seconds//总请求时间

Completerequests:50000//总请求数

Failedrequests:0//失败的请求数

Brokenpipeerrors:0

Totaltransferred:9750000bytes

HTMLtransferred:0bytes

Requestspersecond:1027.75[#/sec](mean)//平均每秒的请求数

Timeperrequest:973.00[ms](mean)//平均每个请求消耗的时间

Timeperrequest:0.97[ms](mean,acrossallconcurrentrequests)//就是上面的时间除以并发数

Transferrate:200.41[Kbytes/sec]received//时间传输速率

ConnnectionTimes(ms)

minmean[+/-sd]medianmax

Connect:01832063.3045003

Processing:28167770.68525579

Waiting:21167770.68525578

Total:283502488.88548639

Percentageoftherequestsservedwithinacertaintime(ms)

50%85//就是有50%的请求都是在85ms内完成的

66%89

75%92

80%96

90%168

95%640

98%984

99%3203

100%48639(lastrequest)

3.用127.0.0.1来访问可以排除网络的因素,不过在Linux上用本机的对外ip访问也是不走网卡,没有网络消耗的

ab帮助:

1.我们知道用ab测试时,最大并发不能超过1024,其实ab本身没有做这个限制,而是系统限制每个进程打开的最大的文件数为1024,ulimit查看如下:

[root@localhost~]#ulimit-a

corefilesize(blocks,-c)0

datasegsize(kbytes,-d)unlimited

filesize(blocks,-f)unlimited

pendingsignals(-i)1024

maxlockedmemory(kbytes,-l)32

maxmemorysize(kbytes,-m)unlimited

openfiles(-n)1024

pipesize(512bytes,-p)8

POSIXmessagequeues(bytes,-q)819200

stacksize(kbytes,-s)10240

cputime(seconds,-t)unlimited

maxuserprocesses(-u)32765

virtualmemory(kbytes,-v)unlimited

filelocks(-x)unlimited

而且openfiles这个选项在一般的系统里是不允许修改成无限制的,如下:

[root@localhost~]#ulimit-nunlimited

bash:ulimit:openfiles:cannotmodifylimit:Operationnotpermitted

但是稍微修改大一些或者是小一些,还是允许的,我们修改的小一些试试:

[root@localhost~]#ulimit-n1020

[root@localhost~]#ulimit-n

1020

[root@localhost~]#

在用ab测试,错误如下:

socket(PF_INET,SOCK_STREAM,IPPROTO_IP)=1019

ioctl(1019,FIONBIO,[1])=0

gettimeofday({1243919682,867688},NULL)=0

connect(1019,{sa_family=AF_INET,sin_port=htons(80),sin_addr=inet_addr("10.55.38.18")},16)=-1EINPROGRESS(Operationnowinprogress)

socket(PF_INET,SOCK_STREAM,IPPROTO_IP)=-1EMFILE(Toomanyopenfiles)

close(-1)=-1EBADF(Badfiledescriptor)

第1019个还能正常打开,下一个就报Toomanyopenfiles的错误了

确实有效,那么我们修改大一些吧:

[root@localhost~]#ulimit-n10240

[root@localhost~]#ulimit-n

10240

[root@localhost~]#

但是我们发现改大却不行,这里却冒出了一个AF_AX25的名词:

socket(PF_INET,SOCK_STREAM,IPPROTO_IP)=1024

ioctl(1024,FIONBIO,[1])=0

gettimeofday({1243919592,254950},NULL)=0

connect(1024,{sa_family=AF_INET,sin_port=htons(80),sin_addr=inet_addr("10.55.38.18")},16)=-1EINPROGRESS(Operationnowinprogress)

socket(PF_INET,SOCK_STREAM,IPPROTO_IP)=1025

ioctl(1025,FIONBIO,[1])=0

gettimeofday({1243919592,255242},NULL)=0

connect(1025,{sa_family=AF_AX25,sa_data="\0P\n7&\22\0\0\0\0\0\0\0\0"},16)=-1EAFNOSUPPORT(Addressfamilynotsupportedbyprotocol)

这个AF_AX25可能是buffer溢出造成的,但不确定哦:)。

另:

-n可以指定最大请求数,但是也不能超过50000哦:)

-vn当n>=2时,可以显示发送的http请求头,和响应的http头及内容;压力测试时不要这么做哦:)

相关推荐