views:

272

answers:

2

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.

+1  A: 

I've used Perf4J, and eventually ditched it because I was already using Spring AOP. I would love to simply integrate the two , but was having trouble with it (because of the Perf4J appenders).

I tried to use Perf4j through annotations and AOP without JMX. You can handle production cfg through configuration files.

Overall, I liked the Perf4j approach but since I was already using Spring for performance monitoring I didn't need perf4j. One thing that Perf4j gives for free is the min/max/standard dev; with other libs you would have to do the math yourself.

I thing perf4j is nice if you don't have any other lib that can provides interception (aspectJ or AOP), but since I already had spring it was easier to implement performance measurement. You can easily expose bean properties through JMX with Spring.

Miguel Ping
+1  A: 

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?

Matthias Wuttke
Matthias, thank you. No, I didn't have a chance to continue using perf4j yet.
grigory