Abstract
用深度学习框架caffe做的project,需要对其进行并发数请求数的压力测试,找到了apachebench(ab)简单的压力测试工具,但在Ubuntu下通过apt-get安装的ab,在处理请求数高于200,300左右的时候就会报错终止apr_socket_recv: Connection reset by peer
,查阅资料显示需要对ab进行重新修改并编译后方可破除这个问题(无论是如何安装的,都要从头开始重新修改编译安装)。
1.下载所需要的源码
apr和apr-util下载:http://apr.apache.org/download.cgi
ab-standalone源码下载:https://code.google.com/p/apachebench-standalone/downloads/list
2.编译安装
分别解压三个压缩包:
ab-standalone-0.1.tar.bz2
apr-1.x.x.tar.gz
apr-util-1.x.x.tar.gz
a.编译apr
$ cd apr
$ ./configure
$ make
$ sudo make install
b.编译apr-util
$ cd apr-util
$ ./configure --with-apr=/usr/local/apr
$ make
$ sudo make install
c.编译ab
修改ab-standalone/ab.c文件
$ cd ab/ab-standalone
$ vim ab.c
到1380行修改成如下:
/* catch legitimate fatal apr_socket_recv errors */
else if (status != APR_SUCCESS) {
err_recv++;
if (recverrok) {
bad++;
close_connection(c);
if (verbosity >= 1) {
char buf[120];
fprintf(stderr,"%s: %s (%d)\n", "apr_socket_recv", apr_strerror(status, buf, sizeof buf), status);
}
return;
} else {
//apr_err("apr_socket_recv", status); // begin
bad++;
close_connection(c);
return; // end
}
}
然后在编译之前将apr-util/include/下的apr_base64.h和apu.h拷贝到ab-standalone文件夹内,否则找不到头文件
开始编译ab
$ make apr-skeleton
$ sudo make ab
$ sudo cp ab apr-skeleton /usr/local/bin/
3.注意
连接库文件问题:
终端中安装: libapr1,否则会出错找不到apr-1:sudo apt-get install libapr1
或者从编译后的usr/local/apr/lib下面将几个文件拷贝到/usr/lib/x86_64-linux-gnu下做链接:
sudo cp /usr/local/apr/lib/libaprutil-1.a /usr/lib/x86_64-linux-gnu/
sudo cp /usr/local/apr/lib/liaprutil-1.so /usr/lib/x86_64-linux-gnu/
sudo cp /usr/local/apr/lib/libaprutil-1.so.0.6.0 /usr/lib/x86_64-linux-gnu/
sudo cp /usr/local/apr/lib/libaprutil-1.la /usr/lib/x86_64-linux-gnu/
cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libaprutil-1.so.0.6.0 libaprutil-1.so.0
sudo ldconfig
同理,不选择apt-get安装,而如此设置libapr1.so.0即可。
4.测试
查看版本:
$ ab -V
This is ApacheBench, Version 2.3 <$Revision$>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
测试并发数:
ab -n 500 -c 500 127.0.0.1 # -n请求数,-c并发数,-n>=-c
This is ApacheBench, Version 2.3 <$Revision$>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: TornadoServer/4.5.2
Server Hostname: 127.0.0.1
Server Port: 1000
Document Path: /
Document Length: 221727 bytes
Concurrency Level: 500
Time taken for tests: 215.661 seconds
Complete requests: 500
Failed requests: 1023
(Connect: 0, Receive: 341, Length: 341, Exceptions: 341)
Write errors: 0
Total transferred: 35272401 bytes
HTML transferred: 35254593 bytes
Requests per second: 2.32 [#/sec] (mean)
Time per request: 215661.110 [ms] (mean)
Time per request: 431.322 [ms] (mean, across all concurrent requests)
Transfer rate: 159.72 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 355 3586.5 0 63141
Processing: 1557 119576 33974.7 127335 182963
Waiting: 0 33466 58718.9 0 182963
Total: 1566 119931 34207.2 127335 210234
Percentage of the requests served within a certain time (ms)
50% 127335
66% 127336
75% 127337
80% 127337
90% 151213
95% 175948
98% 176152
99% 177742
100% 210234 (longest request)
参考
http://shenwang.blog.ustc.edu.cn/%E5%AE%89%E8%A3%85abapachebench-standalone/
http://blog.csdn.net/kimsung/article/details/9422991
https://code.google.com/p/apachebench-standalone/wiki/HowToBuild