对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 50000 -c 100 "http://10.210.215.145/"
结果:
并发数100,请求50000次,试验2次,两次平均时间14.4855s,TPS=50000/14.4855 = 3452
详情如下:
Server Software: Apache/2.2.26
Server Hostname: 10.210.215.145
Server Port: 80
Document Path: /
Document Length: 44 bytes
Concurrency Level: 100
Time taken for tests: 14.333 seconds
Complete requests: 50000
Failed requests: 0
Write errors: 0
Total transferred: 14750295 bytes
HTML transferred: 2200044 bytes
Requests per second: 3488.39 [#/sec] (mean)
Time per request: 28.667 (mean)
Time per request: 0.287 (mean, across all concurrent requests)
Transfer rate: 1004.98 received
Connection Times (ms)
minmean[+/-sd] median max
Connect: 0 2 1.3 1 6
Processing: 1 27 7.7 25 753
Waiting: 1 26 5.7 25 382
Total: 2 29 7.7 27 756
Percentage of the requests served within a certain time (ms)
50% 27
66% 32
75% 33
80% 33
90% 35
95% 36
98% 37
99% 38
100% 756 (longest request)
real 0m14.393s
user 0m0.846s
sys 0m4.538s
下面开始测试memcache
1,下载、安装并且启动memcached-1.4.16
2,设置一个key,如下:
set abc 1 0 44
<html><body><h1>It works!</h1></body></html>
STORED
get abc
VALUE abc 1 44
<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 8888 100 500 1>abc 2>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: Cannot assign requested
TIME_WAIT是什么?
过去的一页,能不要翻就不要翻,翻落了的灰尘会迷了双眼 俄对自己说▌戴任怀只是睡着L天亮就会起来。 不要小看自己,霍金都能当天才,你有什么不行的 寂寞的房间只剩下寂寞的人. 个性签名:一个人可以难过到没有情绪没有言语没有表情 每个人都有缺点,在我面前我可以多给你加一个
页:
[1]