Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have you used Perf4J to collect and analyze performance metrics in Java app? [closed]

Tags:

Did you use Perf4J in your Java application to collect and analyze performance stats?

What was the typical pattern (using log files, utilities, UI, JMX, etc.)?

Did you use annotations and AOP-based features?

Did you use any JMX integration?

How did you handle production configuration?

Did you include performance stats views/reports as a feature in your application?

Please tell if and why you decided on alternative library/approach.

like image 366
topchef Avatar asked Jan 28 '10 21:01

topchef


People also ask

What is Perf4j?

Perf4j is an open source performance logging framework that helps us out here.


2 Answers

I am using Per4j to monitor webservice endpoint performance and also internal service and dao class performance.

I mainly just log the raw performance statistics to a daily rolling file. Then i use the jar on the command line to analyse the data with different timeslices as i please. I often use the -g commandline option to output a html file which i can then open up and view the data visually which is really useful.

I enjoy using Spring AOP with the @Profiled annotation. It makes timing very clean. I had a few doubters regarding perf4j degrading performance, and i could easily offer that i could turn the logging off by removing the TimingAspect from my Spring applicationContext.xml file.

<!-- just remove and all uses of @Profiled do nothing --> <bean id="timingAspect" class="org.perf4j.log4j.aop.TimingAspect"/> 

Becareful about the mean value and note the max value. While doing performance tuning, we had a method call having wild values with a large standard deviation. Most of the values were around the median, however there were a sprinkling of calls which were 100x more than the average. More of user error than anything, but watch out.

I use theAsyncCoalescingStatisticsAppender with a timeslice of 15000, but hardly read the log. Because i have the raw performance logs, I can chop and change that by running perf4j on the command line.

I tried out the JMX integration and it works as promised from the documentation. But I have no real use at the moment for it.

I have plans to expose the data using SNMP and if it's useful i'll contribute.

In all, i recommend Perf4j.

like image 125
JavaRocky Avatar answered Oct 13 '22 17:10

JavaRocky


I am using Perf4J in a client-server application for timing RPC calls. It was quite simple to implement: I only needed to include a few lines of code around the RPC dispatcher servlet to measure each RPC method call. Time measurements are written to a separate log file, aggregated data is kept in memory for usage with the graphing servlet. Configuration was a matter of minutes.

This is an excerpt from the preHandle() method:

request.setAttribute("stopWatch", new CommonsLogStopWatch()); 

This code from the postHandle() method:

LoggingStopWatch stopWatch = (LoggingStopWatch)request.getAttribute("stopWatch"); stopWatch.stop(methodName); 

Here are the relevant sections of my log4j.cfg:

<logger name="org.perf4j.TimingLogger" additivity="false">     <level value="info"/>     <appender-ref ref="CoalescingStatistics"/>     <appender-ref ref="statsAppender"/> </logger>  <appender name="CoalescingStatistics"           class="org.perf4j.log4j.AsyncCoalescingStatisticsAppender">     <param name="TimeSlice" value="60000"/>     <appender-ref ref="graphPatientChart"/> </appender>  <appender name="graphPatientChart"           class="org.perf4j.log4j.GraphingStatisticsAppender">     <param name="GraphType" value="Mean"/>     <param name="TagNamesToGraph" value="getPatientChart,idleNotification"/> </appender>  <appender name="statsAppender" class="org.apache.log4j.DailyRollingFileAppender">     <param name="datePattern" value="'.'yyyy-MM-dd"/>     <param name="file" value="WEB-INF/log/meona-performance.log"/>     <param name="append" value="true"/>     <layout class="org.apache.log4j.PatternLayout">         <param name="ConversionPattern" value="%m%n"/>     </layout> </appender> 

I'd like the graphing servlet to be more interactive: It would be nice if I could choose the tags to be included in the graph. Have you come across an UI application that can be used to analyze the time measurement logs?

like image 34
Matthias Wuttke Avatar answered Oct 13 '22 18:10

Matthias Wuttke