对apache和memcache进行压力测试

时间:2023-03-08 21:11:43
对apache和memcache进行压力测试

工作中经常使用的软件之二:apache和memcache

以前经常听说memcache的TPS能达到几万,但一直也不知道apache的性能到底如何,所以在闲暇之余,就自己做了一下压力测试。

环境:两台开发机,一台施压,一台被压

过程如下:

1,下载、安装并启动apache 2.2.26

2,使用一个简单的网页作为测试目标

<html><body><h1>It works!</h1></body></html>

3,使用apache自带的ab命令,进行压力测试

time ab -n  -c  "http://10.210.215.145/"

结果:

并发数100,请求50000次,试验2次,两次平均时间14.4855s,TPS=50000/14.4855 = 3452

详情如下:

Server Software:        Apache/2.2.
Server Hostname: 10.210.215.145
Server Port: Document Path: /
Document Length: bytes Concurrency Level:
Time taken for tests: 14.333 seconds
Complete requests:
Failed requests:
Write errors:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 3488.39 [#/sec] (mean)
Time per request: 28.667 [ms] (mean)
Time per request: 0.287 [ms] (mean, across all concurrent requests)
Transfer rate: 1004.98 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 1.3
Processing: 7.7
Waiting: 5.7
Total: 7.7 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request) real 0m14.393s
user 0m0.846s
sys 0m4.538s

下面开始测试memcache

1,下载、安装并且启动memcached-1.4.16

2,设置一个key,如下:

set abc
<html><body><h1>It works!</h1></body></html>
STORED
get abc
VALUE abc
<html><body><h1>It works!</h1></body></html>
END

3,使用我自己编写的压力测试脚本进行压力测试,见博客:用epoll进行压力测试

结果:并发数100,请求500*100 = 50000次,试验2次,两次平均时间7.031s,TPS=50000/7.031 = 7111

详情如下:

time ./epoll 10.210.215.145    >abc >abc

real    0m7.099s
user 0m0.292s
sys 0m6.364s

结论:

memorycache的性能远远高于apache的性能,在我的实验中,是两倍在关系,当然实验可能会有误差。

memorycache使用的是libevent,libevent使用了epoll,而apache使用的是select

个人觉得epoll的出现正是为了克服select和poll的不足,所以memorycache性能远远高于apache的性能也不足为怪。

插曲:

当使用我自己的压力测试工具时,老是出现Cannot assign requested错误,原因如下:

我的压力测试脚本进行了50000次连接,也使用了50000个socket,也就是需要50000个端口,但系统的可用端口数是有限制的

我使用的开发机中,可用端口数只有30000多个,所以会造成实验失败。

但可以通过echo 10000 61000 > /proc/sys/net/ipv4/ip_local_port_range来进行修改。

参考文献:

造成socket.error: [Errno 99] Cannot assign requested

TIME_WAIT是什么?