mac环境下 ab 压力测试及问题处理

起因:进行压力测试时,出现一下问题

Benchmarking www.local_test.com (be patient)
socket: Too many open files (24)

$ ab -n 6000 -c 5000 http://www.local_test.com/goods
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.local_test.com (be patient)
socket: Too many open files (24)

检测服务器能够打开文件的数量

Linux ulimit命令用于控制shell程序的资源。

ulimit为shell内建指令,可用来控制shell执行程序的资源。

语法
ulimit [-aHS][-c <core文件上限>][-d <数据节区大小>][-f <文件大小>][-m <内存大小>][-n <文件数目>][-p <缓冲区大小>][-s <堆叠大小>][-t <CPU时间>][-u <程序数目>][-v <虚拟内存大小>]
参数:

-a  显示目前资源限制的设定。
-c <core文件上限>  设定core文件的最大值,单位为区块。
-d <数据节区大小>  程序数据节区的最大值,单位为KB。
-f <文件大小>  shell所能建立的最大文件,单位为区块。
-H  设定资源的硬性限制,也就是管理员所设下的限制。
-m <内存大小>  指定可使用内存的上限,单位为KB。
-n <文件数目>  指定同一时间最多可开启的文件数。
-p <缓冲区大小>  指定管道缓冲区的大小,单位512字节。
-s <堆叠大小>  指定堆叠的上限,单位为KB。
-S  设定资源的弹性限制。
-t <CPU时间>  指定CPU使用时间的上限,单位为秒。
-u <程序数目>  用户最多可开启的程序数目。
-v <虚拟内存大小>  指定可使用的虚拟内存上限,单位为KB。

查看结果:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1418
virtual memory          (kbytes, -v) unlimited

修改为 10000

$ ulimit -n 10000

测试
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 10000
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1418
virtual memory          (kbytes, -v) unlimited

再次压力测试

错误问题:

apr_socket_recv: Connection reset by peer (54)

是由于使用的MacOSX默认自带的ab限制了并发数导致的。

解决办法:下载最新的apache并重新编译,备份原来的ab并将新编译的ab替换到原来的路径。

先下载文件:httpd-2.4.25.tar.bz2,在编译的时候说没有apr和apr-util,先对这两个进行安装;

官网下载地址:http://apr.apache.org/downloa... 和 http://apache.fayea.com/httpd/

//解压
tar -zxvf apr-1.5.2.tar.gz //进入解压后目录
.
/configure --prefix=/usr/local/apr
make
& make install
//同理 tar
-zxvf apr-util-1.5.4.tar.gz
.
/configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
& make install //同理
tar
-zxvf httpd-2.4.25.tar.bz2
.
/configure --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util make & make install

错误问题:

apr_socket_connect(): Operation already in progress (37)

 待解决

猜你喜欢

转载自www.cnblogs.com/smallyi/p/11939463.html