Skip to content


用squid缓存jsp加速lucene搜索

前面尝试了使用nginx负载均衡lucene,效果还不错,但更新维护比较麻烦。 搜索来源中大部分是由连接方式过来,所以大部分的页面内容相同,可以使用缓存的方式重复使用。

方案一:用nginx的proxy stone 方案二:用nginx的ncache 方案三:用Varnish 方案四:用squid

方案一和方案二: 方案一和二是副本概念不会自动更新缓存,需写脚本来控制 都要使用nginx 的rewrite将html转成jsp 修改jsp中分页等连接地址为html 方案二需修改jsp在header中增加max-age

尝试结果: jsp的参数超过了10个,但nginx只支持10个,所以不能缓存所有页面,但可以尝试缓存最常用的关键词第一页。 linux上好像没法将文件缓存起来并且没log,以下是windows上error.log

2008/11/04 16:39:16 [crit] 2828#0: 3 rename() “/proxy_temp/0000000004” to “html/locals.c1gstudio.com/search/” failed (21: Is a directory) while reading upstream, client: 127.0.0.1, server: locals.c1gstudio.com, request: “GET /search/ HTTP/1.1”, upstream: “http://192.168.1.50:8080/search/“, host: “locals.c1gstudio.com” 2008/11/04 16:39:19 [crit] 2828#0: 1 rename() “/proxy_temp/0000000013” to “html/locals.c1gstudio.com/search/result.jsp?keyword=+%E7%BC%96%E8%BE%91&city=0&type=0&do=1” failed (2: No such file or directory) while reading upstream, client: 127.0.0.1, server: locals.c1gstudio.com, request: “GET /search/result.jsp?keyword=+%E7%BC%96%E8%BE%91&city=0&jobtype=0&do=1 HTTP/1.1”, upstream: “http://192.168.1.50:8080/search/result.jsp?keyword=+%E7%BC%96%E8%BE%91&city=0&type=0&do=1“, host: “locals.c1gstudio.com”, referrer: http://locals.c1gstudio.com/search/

貌似不必rewrite也可缓存。=_=!!!

方案三: 缓存放在内存里,软件重启后需重新生成,瞬时并发比较大 网卡流量也比较多,性能也比squid差。 参考it流言终结者的比较 IT流言终结者1续篇:varnish vs squid IT流言终结者1:Varnish vs Squid http://www.hiadmin.com/category/service/squid-app/

方案四: 以前有架设过,改改配置就可以上了。 选择squid2.6stable22,据测试性能稳定。

架设参考 squid 安装 https://blog.c1gstudio.com/archives/130

squid.conf中 开1.5G内存,4G硬盘 cache_store_log none access_log none

refresh_pattern -i .html$  60       25%     240 refresh_pattern -i .htm$   60       25%     240 refresh_pattern -i .jsp$   5       25%     20

refresh_pattern -i .gif$   1440    50%     2880      ignore-reload refresh_pattern -i .jpg$   1440    50%     2880      ignore-reload refresh_pattern -i .jpeg$  1440    50%     2880     ignore-reload refresh_pattern -i .png$   1440    50%     2880      ignore-reload

总结: 最终架构是 nginx(80)->squid(81)->tomcat(8080) nginx 跑在80端口代理81 squid 跑81端口代理远程的tomcat (squid跑在80会报access denied,忘改这个了acl Safe_ports port 81) tomcat 在另一台机器上

jsp中header增加max-age=3600和相应expires,让页面在ie中缓存一小时,squid中缓存5~20分钟。

目前的负载 跑nginx和squid的 load average: 0.18, 0.14, 0.08 以前是load为1左右 跑tomcat的 load average: 1.57, 1.41, 1.28 以前load为3左右

现在改动程序只需改动一台机器,结果很满意哈~

 

Posted in Nginx, Squid/varnish.

Tagged with , , , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. Confluence: 技术论坛 linked to this post on 2009/04/28

    高可靠高并发Web应用架构研究…

    HTTP协议标准及相关技术        HTTP状态码一览表        http 头信息详解        如何查看HTTP协议头部信息…



Some HTML is OK

or, reply to this post via trackback.