When you are working in the large scale industries it is very important to track the perf numbers at each and every level. In the software development cycle half the time goes in the development and testing half the time goes in the performance tuning. And one should optimize at every possible step.
If we look at at the any web giant companies, and mainly working on SaaS based services their main goals will be meeting their SLA promises. Typically most of the developers will do like putting the stopwatch timers around the method executions and calculate the execution time. Which have their own limitations, we can discuss later.
In this article I am going to discuss about the method level tracing by the spring AOP provided tracing system.
Here I am expecting:
1. Your application/service is multi threaded
2. Single thread execution per request
3. Spring is your part of web application
4. Log4j/slf4j is your logger
Here is the very simple configurations you have to add to the spring beans.
<bean id="timingAdvice" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />
<aop:config>
<aop:advisor pointcut="execution(* <package>.<class>.*(..))" advice-ref="timingAdvice"/>
</aop:config>
You can refer here for how to write a execution point cuts.
For working code example you can refer my github repo here.
https://github.com/shiva404/perflogging-SpringProvided
The perf log will be printed package along with class and method with running time is millis.
StopWatch 'shiv.exp.ITestResource.getReq': running time (millis) = 1
For working code example you can refer my github repo here.
https://github.com/shiva404/perflogging-SpringProvided
The perf log will be printed package along with class and method with running time is millis.
StopWatch 'shiv.exp.ITestResource.getReq': running time (millis) = 1
No comments:
Post a Comment