varnish,squid,apache,nginx缓存文件比较
一,测试环境
1,硬件是奔腾双核,机子三年前买的。系统是archlinux
2,测试varnish和squid的时候,web服务用的apache
3,测试apache的时候,启动了5个进程,不过随着压力的增加,进程会增加的。
4,测试Nginx的时候,启动了十个Nginx进程,20个php-cgi进程
5,varnish,squid,Nginx用的是反向代理的形势,也就是说访问图片的时候,要先透过缓存工具
二,测试
1,varnish
[root@BlackGhost bin]# /usr/local/bin/webbench -c 100 -t 20 http://127.0.0.1:8080/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1:8080/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.
Speed=476508 pages/min, 47258114 bytes/sec.
Requests: 158836 susceed, 0 failed.
varnish的缓存效率命中率真的好高,看下图:
访问了这么次,没有缓存只有一次,效率真的很高。
2,squid
[root@BlackGhost bin]# /usr/local/bin/webbench -c 100 -t 20 http://localhost:9000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost:9000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.
Speed=133794 pages/min, 7475018 bytes/sec.
Requests: 44598 susceed, 0 failed.
从测试效果来说,squid挺让我失望的,在测试前,我心里是这样估计的,缓存最好的是varnish,其次是squid,然后Nginx,最后是apache,现在呢,squid是最差的。后来我看了一下log文件,发现正常情况下,缓存和没有缓存的比率不是1:2,如果在高压力下,缓存和没有缓存的比率更小。
3,apache
[root@BlackGhost conf]# /usr/local/bin/webbench -c 100 -t 20 http://localhost/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.
Speed=160890 pages/min, 15856005 bytes/sec.
Requests: 53630 susceed, 0 failed.
4,nginx
[root@BlackGhost conf]# /usr/local/bin/webbench -c 100 -t 20 http://localhost:10000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost:10000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif
100 clients, running 20 sec.
Speed=304053 pages/min, 30121517 bytes/sec.
Requests: 101351 susceed, 0 failed.
从上面的测试结果我们可以发现,varnish > nginx > apache > squid,我想这个结果,根大家预期的结果有点出入,因为squid做老牌文件缓存工具怎么会这么差呢,squid的命中率低,我在网上查了一下,很多人都是这样的,这个可能根个人配置有关系,也许真正的高手,才能让squid发挥最大功力。