Ticket #127 (closed 优化: fixed)
squid 缓存分析
| Reported by: | chenchongqi | Owned by: | yuanhuoqing |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | 报价库 | Version: | 报价库5.0 |
| Keywords: | Cc: | ||
| Due Date: |
Description (last modified by chenchongqi) (diff)
网络同事发现,报价前台的squid缓存命中率很低接近0,于是我们一起展开了分析。
- 打开squid的accesslog日志后发现,readintf没有加expire的设置,只是设了r系统的缓存时间,所以他不会被squid缓存,如此一来resin的压力就大了,对r系统的依赖也大:
boolean important=url.indexOf("priority")!=-1; //优先,缓冲15分钟 boolean fixed=url.indexOf("fixed")!=-1; //不更新,缓冲24小时 //影响squid的缓冲时间 int cacheTime=3600; //缓冲1小时 if (important) cacheTime=900; //重要接口缓冲15分钟 if (fixed) cacheTime= 86400;
增加头信息后,可以看到squid的命中率上升到了30%左右:
response.setHeader("Cache-Control", "max-age=3600");
response.setDateHeader("Last-Modified", System.currentTimeMillis());
response.setDateHeader("Expires", System.currentTimeMillis()+3600000);
- 想要进一步提高缓存命中率,减少应用的流量压力,需要再对日志进行分析。
- squid日志文件access.log.gz。
- 手动脚本分析结果,请求总数9万,可见readintf的请求占了62%,而readintf的命中率不到一半,另外占总请求数14%的priceareanav则基本没有命中,因此后续缓存的优化还是要围绕这两个地方来进行。
- 日志里还发现,TCP_REFRESH_MISS占了四分之一左右,这种情况部分是浏览器端ctrl+F5强刷穿透过来的,这类请求头一般都带着paragma:no-cache,如果时间不是特别敏感的话,可以考虑设置squid的ignore-reload开关,屏蔽强刷信号。
awk -F\" '{where=match($2,/\?/);if(where) where=where-5; else where=length($2)-13;printf( "%s %s\n",substr($2,5,where),substr($7,2,match($7,/:/)-1))}' access.log|sort|uniq -c|sort -nr|more 25673 http://product.pconline.com.cn/readIntf.jsp TCP_MEM_HIT: 16798 http://product.pconline.com.cn/readIntf.jsp TCP_MISS: 13989 http://product.pconline.com.cn/readIntf.jsp TCP_REFRESH_MISS: 10148 http://product.pconline.com.cn/_priceAreaNav.jsp TCP_MISS: 2771 http://product.pconline.com.cn/_priceAreaNav.jsp TCP_REFRESH_MISS: 2507 http://product.pconline.com.cn/readIntf.jsp TCP_HIT: 1069 http://product.pconline.com.cn/productadvanceresult.jsp TCP_MISS: 1007 http://product.pconline.com.cn/createPriceTrendData.jsp TCP_MISS: 937 http://product.pconline.com.cn/intf/_search_json.jsp TCP_MISS: 341 http://product.pconline.com.cn/readIntf.jsp TCP_REFRESH_HIT: 206 http://product.pconline.com.cn/v_news.jsp TCP_MISS: 71 http://product.pconline.com.cn/intf/_cri_4choose_json_utf8.jsp TCP_MISS: 70 http://gpc.pcgames.com.cn/gamehardware/selectProduct.jsp TCP_MISS: 40 http://product.pconline.com.cn/intf/_search_ultrabook_json.jsp TCP_MISS: 40 http://product.pconline.com.cn/genCustomPriceRangeStaticPath.jsp TCP_MISS: 27 http://product.pconline.com.cn/_relatedArticle.jsp TCP_REFRESH_MISS: 22 http://product.pconline.com.cn/_priceAreaNav.jsp TCP_REFRESH_HIT: 21 http://product.pconline.com.cn/productadvancesearch.jsp TCP_MISS: 17 http://product.pconline.com.cn/_relatedArticle.jsp TCP_MISS: 15 http://product.pconline.com.cn/productSoResult.jsp TCP_MISS: 14 http://product.pconline.com.cn/v_search_box.jsp TCP_MISS: 11 http://product.pconline.com.cn/productpconlinecomcn.rar TCP_MISS: 11 http://product.pconline.com.cn/pconline.com.cn123.rar TCP_MISS: 11 http://product.pconline.com.cn/intf/_cri_json.jsp TCP_MISS: 10 http://product.pconline.com.cn/pconline.com.cn.zip TCP_MISS: 10 http://gpc.pcgames.com.cn/gamehardware/game_diy_prints.jsp TCP_MISS:
Attachments
Change History
Note: See
TracTickets for help on using
tickets.
![(please configure the [header_logo] section in trac.ini)](http://www1.pconline.com.cn/hr/2009/global/images/logo.gif)
