Ticket #76 (closed 优化: fixed)

Opened 14 years ago

Last modified 14 years ago

产品库动态产品文章、图片读取的代码优化

Reported by: huangxianduan Owned by: huangxianduan
Priority: major Milestone:
Component: 产品库 Version: 产品库3.0
Keywords: 数据库优化 Cc:
Due Date: 15/12/2011

Description (last modified by chenchongqi) (diff)

由于产品库动态数据库的产品文章表访问频率非常的高,虽然单句执行成本低,但是一个小时的访问次数达到18万,占了数据库服务器比较多资源。

检查代码发现动态的页面几乎都是公用了OuterAction的detail方法,这个方法里面会把所有跟产品相关的所有信息查出来,不管当前的访问请求是否需要这些信息,再加上有些查询是没有做mc缓存的,而且文章表的数据量比较大,这样就导致了频繁的读取造成数据库服务器负载高

优化:检查代码判断是否需要文章和图片数据。如果不需要就不做数据的读取,减少对数据库读取的频率,降低数据库服务器的压力。

Attachments

SQL.xls Download (72.0 KB) - added by chenchongqi 14 years ago.

Change History

comment:1 Changed 14 years ago by huangxianduan

优化后的相关代码:

if(template != null && (template.indexOf("product_1.jsp") != -1 || template.indexOf("wap_product.jsp") != -1)){
	request.setAttribute(CURRENT_PRODUCT_PIC, oProduct.getProductPicWEB(cp));
}
if(template != null && (template.indexOf("product_4.jsp") != -1
			|| template.indexOf("product_4_art.jsp") != -1 || template.indexOf("product_5.jsp") != -1)) {
	request.setAttribute(CURRENT_ARTICLE_LINK, oProduct.getProductArticleLinkWEB());
}
Last edited 14 years ago by huangxianduan (previous) (diff)

comment:2 Changed 14 years ago by huangxianduan

  • Status changed from new to closed
  • Resolution set to fixed

comment:3 Changed 14 years ago by chenchongqi

  • Keywords 数据库优化 added; 优化 removed

Changed 14 years ago by chenchongqi

comment:4 Changed 14 years ago by chenchongqi

  • Status changed from closed to reopened
  • Resolution fixed deleted

更新上去后没有明显改善,需要再次检查。

comment:5 Changed 14 years ago by chenchongqi

  • Description modified (diff)

comment:6 Changed 14 years ago by yuanhuoqing

经过贤端的优化后发现产品库动态根据产品id查文章的sql每小时仍有16w多,调用方法:product.getProductArticleLinkWEB();进一步分析发现这个方法在好多接口上调用,接口的缓存key都是产品id加其他参数组成,缓存过期时间都是1小时,所以缓存的命中率很低,同样好些接口业务上无须查文章却仍调用了此方法,造成多余的查询,

进一步优化方案:
1、把缓存过期调整为8小时;
2、无须查文章的去掉调用查文章的方法;
代码:

<%
Product product = ProductManager.getInstance().getProduct(id);
ProductTypeWEB type = new ProductTypeWEB(TypeManager.getInstance().getType(product.getTypeId()));
ConfigProfile cp = ConfigProfileManager.getInstance().getAncestorConfigProfile(product.getTypeId());
ProductPicWEB picture = product.getProductPicWEB(cp);
ProductArticleLinkWEB link = null;
List groups = product.getProductItemGroupWEB(cp);
request.setAttribute("product",product);
%>
<c:set var="HTML">
<%if (style.equals("n")){
 link = product.getProductArticleLinkWEB();%>
	<%@include file="/service/tmpl/show_product_item_n.html"%>
<%}else if (style.equals("r")){%>
	<%@include file="/service/tmpl/show_product_item_r.html"%>
<%}else if (style.equals("rn") || "r-n".equals(style)){%>
	<%@include file="/service/tmpl/show_product_item_r_n.html"%>
<%}else if (style.equals("x")){
 link = product.getProductArticleLinkWEB();%>
	<%@include file="/service/tmpl/show_product_item_x.html"%><%--电脑网文章页右侧 --%>
<%}else if (style.equals("x2")){
 link = product.getProductArticleLinkWEB();%>
	<%@include file="/service/tmpl/show_product_item_x2.html"%><%--电脑网文章页右侧 --%>
<%}else if (style.equals("no") || "n-o".equals(style)){
 link = product.getProductArticleLinkWEB();%>
	<%@include file="/service/tmpl/show_product_item_no.html"%><%--2011-08-31增加的展现样式--%>
<%}else if (style.equals("m")){%>
	<%@include file="/service/tmpl/show_product_item_m.html"%><%--增加商城样式--%>
<%}else{
link = product.getProductArticleLinkWEB();%>
	<%@include file="/service/tmpl/show_product_item_js.html"%>
<%}%>
</c:set>

comment:7 Changed 14 years ago by chenchongqi

  • Status changed from reopened to closed
  • Resolution set to fixed

上线时间12.23,等下个月oracle报告出炉再看看资源消耗率的情况。

Note: See TracTickets for help on using tickets.