ab压力测试报错: apr_socket_recv: Connection reset by peer (104)

使用ab对网站进行压力测试,开始设置并发500,可以正常使用,当设置并发为1000,则报错:

apr_socket_recv: Connection reset by peer (104)

改服务端apache的maxclients参数,调大最大打开文件数,都不解决问题,最后才发现是因为ab的源码对ab的并发有限制,修改源码重新编译apache:

修改源码support目录下的ab.c文件,大概在1369行,修改为:

return;
} else {
//apr_err("apr_socket_recv", status);
bad++;
close_connection(c);
return;

最后贴上ab的参数使用:

/usr/local/apache2/bin/ab -c 3000 -n 5000 http://192.168.1.43/index.html

http://blog.chinaunix.net/uid-24443760-id-3758092.html

$ ab help
E:xamppapacheinab.exe: invalid URL
Usage: E:xamppapacheinab.exe [options] [http://]hostname[:port]/path
Options are:
    -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.
    -m method       Method name
    -h              Display usage information (this message)
ab -n 200 -c 10  -T 'application/json' -p post.json http://127.0.0.1:8002/webapi/

执行此命令目录下,放置post.json文件:

{
    "jsonrpc": "2.0",
    "method": "test_method",
    "params": [1442885518, 1442892718,"testDomain_80"],
    "id": "1"
}

https://www.jianshu.com/p/66ad2f9570f8
https://www.cnblogs.com/jinjiangongzuoshi/p/5426034.html
https://gist.github.com/kelvinn/6a1c51b8976acf25bd78

Downloading Apache for Windows

The Apache HTTP Server Project itself does not provide binary releases of software, only source code. Individual committers may provide binary packages as a convenience, but it is not a release deliverable.

If you cannot compile the Apache HTTP Server yourself, you can obtain a binary package from numerous binary distributions available on the Internet.

Popular options for deploying Apache httpd, and, optionally, PHP and MySQL, on Microsoft Windows, include:

http://www.apachehaus.com/cgi-bin/download.plx
http://www.apachelounge.com/download/
http://bitnami.com/stack/wamp
http://www.wampserver.com/
http://www.apachefriends.org/en/xampp.html

https://httpd.apache.org/docs/current/platform/windows.html#down

ab -n 100 -c 10 http://www.baidu.com/s

-n 表示请求数,-c 表示并发数.
s为path,表示指定测试地址,不指定可能会报”ab: invalid url” 错误.
另外还有-t 表示多少s内并发和请求

测试出来的数据如下:

D:Apache24in>ab -n 100 -c 10 http://www.baidu.com/s
This is ApacheBench, Version 2.3 <$Revision: 1807734 $> 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.baidu.com (be patient).....done

Server Software:        BWS/1.1   
##服务器软件和版本
Server Hostname:        www.baidu.com  
##请求的地址/域名
Server Port:            80   
##端口

Document Path:          /s  
##请求的路径
Document Length:        112435 bytes  
##页面数据/返回的数据量

Concurrency Level:      10   
##并发数
Time taken for tests:   4.764 seconds  
##共使用了多少时间 
Complete requests:      100  
##请求数 
Failed requests:        99  
##失败请求  百度为什么失败这么多,应该是百度做了防范  
   (Connect: 0, Receive: 0, Length: 99, Exceptions: 0)
Total transferred:      11342771 bytes  
##总共传输字节数,包含http的头信息等 
HTML transferred:       11247622 bytes  
##html字节数,实际的页面传递字节数 
Requests per second:    20.99 [#/sec] (mean) 
 ##每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量 
Time per request:       476.427 [ms] (mean)   
##用户平均请求等待时间 
Time per request:       47.643 [ms] (mean, across all concurrent requests)  
##服务器平均处理时间,也就是服务器吞吐量的倒数 
Transfer rate:          2325.00 [Kbytes/sec] received
 ##每秒获取的数据长度

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       22   41  12.4     39      82
##连接的最小时间,平均值,中值,最大值
Processing:   113  386 211.1    330    1246
##处理时间
Waiting:       25   80  43.9     73     266
##等待时间
Total:        152  427 210.1    373    1283
##合计时间

Percentage of the requests served within a certain time (ms)
  50%    373   
## 50%的请求在373ms内返回 
  66%    400   
## 60%的请求在400ms内返回 
  75%    426
  80%    465
  90%    761
  95%    930
  98%   1192
  99%   1283
 100%   1283 (longest request)

ab是apache自带的网站压力测试工具。 
使用起来非常的简单和方便。 
不仅仅是可以apache服务器进行网站访问压力测试,还可以对其他类型的服务器进行压力测试。 
比如nginx,tomcat,IIS等

首先当然是下载安装了。 
在这里只讲window下在下载安装 
官方下载地址:,(https://www.apachehaus.com/cgi-bin/download.plx)

下载完成后解压 
我就直接解压到d盘的apacheab中去了 
修改解压根目录下的conf/httpd.conf文件的端口配置,默认是80端口,应该是被占用了,无法安装,可以自行修改为其他,我在这里修改为8088端口

然后输入命令安装:

httpd -k install

第一次安装错误是因为端口没有改,被占用了,应该是被iis占用的。

https://blog.csdn.net/qq_26525215/article/details/79182674





原文地址:https://www.cnblogs.com/softidea/p/5740911.html