系统有时候,客户抱怨很慢?我们总是很自信的说,那是不可能的,真的吗?我们都很唯物主义,我们要用事实说话。怎么查?拍脑袋?去看密密麻麻的sql语句?对正在电脑前的你似乎是郁闷的一天,度日如年啊,我勒个去。大概都知道struts2有个牛叉的功能叫做拦截器,肯定有人会说这个东西我知道
不就是动态代理(jdk proxy,or cglib)?对 就是这个东西,魔法的操作java字节码,实现脚本才能实现的某些功能,似乎很赞!
来入主题了:
写一个拦截器,上代码:import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
 * <pre>
 * 
 * </pre>
 *
 * @author chengjun
 * @version $Id: TimerInterceptor.java, v 0.1 2011-5-10 上午09:24:06 chengjun Exp $
 */
public class TimerInterceptor extends AbstractInterceptor {    private static final long serialVersionUID = -4979445183812792788L;
private static final Log log = LogFactory.getLog(TimerInterceptor.class); /** 
 * @param invocation
 * @return
 * @throws Exception
 * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
 */
@Override
public String intercept(ActionInvocation invocation) throws Exception {
long startTime = System.currentTimeMillis();//计算开始日期
String result = invocation.invoke();
long executionTime = System.currentTimeMillis() - startTime;
StringBuffer message = new StringBuffer(100);
message.append("###Executed action [");
String namespace = invocation.getProxy().getNamespace();
if ((namespace != null) && (namespace.trim().length() > 0)) {
message.append(namespace).append("/");
}
message.append(invocation.getProxy().getActionName());
message.append("'s method called ");
message.append(invocation.getProxy().getMethod());
message.append("] took ").append(executionTime).append(" ms.");
log.info(message.toString()); return result; }}怎么配置我不说了,大家去找 google大神吧,然后 放到线上去,执行个几天
就得到下面的数据:是不是很欣喜若狂?
[110514 00:18:58][tms] INFO [http-0.0.0.0-8080-10] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_findStationScanedDo's method called findStationScanedDo] took 2273 ms.
[110514 00:20:15][tms] INFO [http-0.0.0.0-8080-12] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3155 ms.
[110514 00:20:22][tms] INFO [http-0.0.0.0-8080-6] TimerInterceptor.intercept(47) | ###Executed action [//tmsFinance_export's method called export] took 1263 ms.
[110514 00:20:43][tms] INFO [http-0.0.0.0-8080-12] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3034 ms.
[110514 00:20:46][tms] INFO [http-0.0.0.0-8080-10] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_findStationScanedDo's method called findStationScanedDo] took 2270 ms.
[110514 00:20:55][tms] INFO [http-0.0.0.0-8080-10] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_exportStationScanedDo's method called exportStationScanedDo] took 1931 ms.
[110514 00:22:10][tms] INFO [http-0.0.0.0-8080-6] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 2973 ms.
[110514 00:22:19][tms] INFO [http-0.0.0.0-8080-14] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 1221 ms.
[110514 00:23:03][tms] INFO [http-0.0.0.0-8080-25] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3036 ms.
[110514 00:23:04][tms] INFO [http-0.0.0.0-8080-1] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3128 ms.
[110514 00:26:37][tms] INFO [http-0.0.0.0-8080-26] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_findStationScanedDo's method called findStationScanedDo] took 2241 ms.
[110514 00:26:44][tms] INFO [http-0.0.0.0-8080-35] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_exportStationScanedDo's method called exportStationScanedDo] took 2253 ms.
[110514 00:29:02][tms] INFO [http-0.0.0.0-8080-25] TimerInterceptor.intercept(47) | ###Executed action [//tmsStaffAllocation_allocationOnTimeConfirm's method called allocationOnTimeConfirm] took 1000 ms.
[110514 00:29:49][tms] INFO [http-0.0.0.0-8080-35] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3029 ms.
[110514 00:30:18][tms] INFO [http-0.0.0.0-8080-35] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3147 ms.
[110514 00:33:02][tms] INFO [http-0.0.0.0-8080-19] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3197 ms.
[110514 00:33:24][tms] INFO [http-0.0.0.0-8080-35] TimerInterceptor.intercept(47) | ###Executed action [//tmsStationCheck_view's method called view] took 3158 ms.
[110514 00:33:44][tms] INFO [http-0.0.0.0-8080-10] TimerInterceptor.intercept(47) | ###Executed action [//getOrder_printCheckSigle's method called printCheckSigle] took 94770 ms.下面简单了,大学学到的概率统计排上用途了,
什么方差?统计图,这个可以找××。他是报表达人撒。根据时间倒排序,找到相应的action,然后调优可以启航了。