Thursday, November 25, 2004

Integrate JAMon with Spring

JAMon is a tool to monitor performance of application components. It's
very useful to determine bottlenecks on application and find the impacted component. It provides too statistics on calls ( between the start and the end of monitors ).

This tool can be download at the following url:
http://sourceforge.net/project/showfiles.php?group_id=96550
and you can find its documentations on these sites:
http://jamonapi.sourceforge.net/
http://www.javaperformancetuning.com/tools/jamon/index.shtml

To install it in your application, only JAMon.jar must be in your classpath.


Spring already has an aop interceptor to measure performance of application components based on commons-logging. The idea is to provide a simple JAMon interceptor to start monitor before the call and end it after the call.

It provides too facilities to name the JAMon monitor with class and method names.


The method getMonitorName determines the monitor name:




protected String getMonitorName(MethodInvocation invocation) {
StringBuffer monitorName=new StringBuffer();
monitorName.append(
invocation.getMethod().getDeclaringClass().getName());
monitorName.append(" ( ");
monitorName.append(invocation.getMethod().getName());
monitorName.append(" )");
return monitorName.toString();
}


The Spring AOP interceptor is simple:



import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;

public class PerfIntercepteur implements MethodInterceptor {

protected String getMonitorName(MethodInvocation invocation) {
StringBuffer monitorName=new StringBuffer();
monitorName.append(
invocation.getMethod().getDeclaringClass().getName());
monitorName.append(" ( ");
monitorName.append(invocation.getMethod().getName());
monitorName.append(" )");
return monitorName.toString();
}

public Object invoke(MethodInvocation invocation) throws Throwable {
Monitor mon=MonitorFactory.start(getMonitorName(invocation));
Object rval=invocation.proceed();
mon.stop();
return rval;
}
}


and you can configure it in this way:


<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
...
<bean id="perfInterceptor" class="aop.PerfIntercepteur"/>

<bean id="autoProxyCreator" class="org.springframework.aop.framework.
autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<idref local="perfInterceptor" />
</list>
</property>
<property name="beanNames">
<list>
<idref local="service" />
</list>
</property>
</bean>
</beans>


The aim is to plug the JAMon interceptor on the component of the application layer to identifity the component that has performance problem ( from presentation layer to dao layer ).

10 comments:

Dmitriy Kopylenko said...

Thierry,

I've added org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor
to the Spring core. It should be available in 1.1.3

Dmitriy Kopylenko said...

Thierry,

I've added JamonPerformanceMonitorInterceptor to the Spring core.

templth said...

Dimitry,

I'm really glad that you have added to the Spring Core!!
Thanks to tell me this.
Thierry

Drunk Girl said...

Hi, what a great page! Really enjoyed it, keep up the great work!
spy gadgets

Drunk Girl said...

Hi, what a great page! Really enjoyed it, keep up the great work!
007 spy gadget

Bud Wiser said...

Great blog, fully enjoyed it! spy tools

Official play station and xbox mod chips said...

Motokata Professional High Speed Money Counter And Counterfeit Machine
ps2 game shark
Never get ripped off again! Never make accounting errors again! Never waste your time counting again! Our Professional High Speed Money Counter and Counterfeit Detector is fast and accurate.

Faster than a speeding bank teller! Is it real or counterfeit?

How quickly can you count 900 $20 bills? We bet you can't do it in a minute, while spotting phony bills.

This incredibly portable machine is that fast and that smart. Whether you're a shop owner or weekend swap meet vendor, you'll never have to worry when someone hands you a crisp new $20 bill.

The counterfeit detection system is powered by advanced Motorola circuitry providing a highly accurate verification system. With dual infrared and fluorescent detection ps2 game shark

Benezit Decoracion said...

If you want a good jamon visit Spanishtaste shop www.spanishtaste.es

Benezit Decoracion said...

Jamon

dghnfgj said...

EVEN by wow gold the standards gold in wow of the worst financial buy wow gold crisis for at least wow gold cheap a generation, the events of Sunday September 14th and the day before were extraordinary. The weekend began with hopes that a deal could be struck,maplestory mesos with or without government backing, to save Lehman Brothers, America''s fourth-largest investment bank.sell wow gold Early Monday buy maplestory mesos morning Lehman maplestory money filed for Chapter 11 bankruptcy protection. It has more than maplestory power leveling $613 billion of debt.Other vulnerable financial giants scrambled maple money to sell themselves or raise enough capital to stave off a similar fate. billig wow gold Merrill Lynch, the third-biggest investment bank, sold itself to Bank of America (BofA), an erstwhile Lehman suitor,wow power leveling in a $50 billion all-stock deal.wow power leveling American International Group (AIG) brought forward a potentially life-saving overhaul and went maple story powerleveling cap-in-hand to the Federal Reserve. But its shares also slumped on Monday.