apache ab压力测试报错

来源:互联网 发布:易语言ce修改器源码 编辑:程序博客网 时间:2024/06/01 08:05

今天用apache 自带的ab工具测试,当并发量达到1000多的时候报错如下:
[root@aa~]# This is ApacheBench, Version 2.3 <Revision:655654>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.176 (be patient)
Completed 300 requests
Completed 600 requests
Completed 900 requests
apr_socket_recv: Connection reset by peer (104)
Total of 1085 requests completed

查看应用服务器和数据库均未报错,连接被重置,bingyi了以下,apr_socket_recv这个是操作系统内核的一个参数,在高并发的情况下,内核会认为系统受到了SYN flood攻击,会发送cookies(possible SYN flooding on port 80. Sending cookies),这样会减慢影响请求的速度,所以在应用服务武器上设置下这个参数为0禁用系统保护就可以进行大并发测试了:

# vim /etc/sysctl.conf net.ipv4.tcp_syncookies = 0# sysctl -p

然后就可以超过1000个并发测试了。

另附其他系统内核参数说明:

net.ipv4.tcp_syncookies = 0  #此参数是为了防止洪水攻击的,但对于大并发系统,要禁用此设置net.ipv4.tcp_max_syn_backlog#参数决定了SYN_RECV状态队列的数量,一般默认值为512或者1024,即超过这个数量,系统将不再接受新的TCP连接请求,一定程度上可以防止系统资源耗尽。可根据情况增加该值以接受更多的连接请求。net.ipv4.tcp_tw_recycle#参数决定是否加速TIME_WAIT的sockets的回收,默认为0。net.ipv4.tcp_tw_reuse#参数决定是否可将TIME_WAIT状态的sockets用于新的TCP连接,默认为0。net.ipv4.tcp_max_tw_buckets#参数决定TIME_WAIT状态的sockets总数量,可根据连接数和系统资源需要进行设置。 

另外ab中自带参数
-r Don’t exit on socket receive errors.
可以避免并发过大出现错误,从而实现大并发测试,建议使用此方法。

ab 的各种参数

    -n requests     Number of requests to perform    -c concurrency  Number of multiple requests to make at a time    -t timelimit    Seconds to max. to spend on benchmarking                    This implies -n 50000    -s timeout      Seconds to max. wait for each response                    Default is 30 seconds    -b windowsize   Size of TCP send/receive buffer, in bytes    -B address      Address to bind to when making outgoing connections    -p postfile     File containing data to POST. Remember also to set -T    -u putfile      File containing data to PUT. Remember also to set -T    -T content-type Content-type header to use for POST/PUT data, eg.                    'application/x-www-form-urlencoded'                    Default is 'text/plain'    -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.    -q              Do not show progress when doing more than 150 requests    -l              Accept variable document length (use this for dynamic pages)    -g filename     Output collected data to gnuplot format file.    -e filename     Output CSV file with percentages served    -r              Don't exit on socket receive errors.    -h              Display usage information (this message)    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)    -f protocol     Specify SSL/TLS protocol                    (SSL3, TLS1, TLS1.1, TLS1.2 or ALL)
- n请求执行的请求数- c多次请求的并发数- t限时秒到最大值。花在基准测试这意味着- n 50000- s超时秒到最大值。等待每个响应默认值为30秒- b窗口大小的TCP发送/接收缓冲区,以字节为单位- b地址地址在发送连接时绑定-p postfile文件,包含要发布的数据。记住也要设置- t-u putfile文件中包含的数据。记住也要设置- t- t内容类型的内容类型标题用于POST / PUT数据。“应用程序/ x-www -表单- urlen编码”默认是“text / plain”-v verbosity有多少故障排除信息打印- w打印结果在HTML我用HEAD代替GET- x属性字符串作为表属性插入- y属性字符串作为tr属性插入- z属性字符串作为td或th属性插入- c属性添加cookie。Apache = 1234。(重复)- h属性添加任意标题行。“接受编码:gzip插入所有正常的标题行。(重复)属性添加基本的WWW认证,属性是一个冒号分隔的用户名和密码。- p属性添加基本代理身份验证,属性是一个冒号分隔的用户名和密码。- x代理:使用端口Proxyserver和端口号- v打印版本号,退出- k使用HTTP KeepAlive功能- d不显示百分比表。- s不显示置信估计者和警告。当超过150个请求时,q没有显示进展- l接受可变文档长度(用于动态页面)- g文件名输出数据到gnuplot格式文件。- e文件名输出CSV文件的百分比- r不退出套接字接收错误。- h显示使用信息(此消息)- z ciphersuite指定SSL / TLS密码套件(见openssl密码)- f协议指定SSL / TLS协议(SSL3,TLS1,TLS1.1,TLS1.2或全部)
原创粉丝点击