id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	due_date
127	squid 缓存分析	chenchongqi		"网络同事发现，报价前台的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日志文件。
 * 手动脚本分析结果：
{{{
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:
}}}"	优化	new	major		报价库					
