performance analysis and monitoring with perf4j
DESCRIPTION
This is a lightning presentation given by Sudhan Kanade to our team for the purpose of knowledge sharing in support of our efforts to create a culture of learning.TRANSCRIPT
![Page 1: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/1.jpg)
Performance Analysis and Monitoring with Perf4jCode timing, logging, analyzing and
monitoring tool
Sudhan Kanade
![Page 2: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/2.jpg)
Why do we need Perf4J
• Code works on dev / stage env
• Scalability
• Distributed application
1
![Page 3: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/3.jpg)
Analogy: Perf4J to Log4J
• Log4j : System.out.println()
• Perf4J : System.currentTimeMillis()
• Can log similarly to any appenders defined in log4j.
• Can use AspectJ / Spring AOP
2
![Page 4: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/4.jpg)
What difference Perf4J makes:
• Without Perf4Jlong start = System.currentTimeMillis();// execute the block of code to be timedlog.info("ms for block n was: " + (System.currentTimeMillis() -
start));
• With Per4JStopWatch stopWatch = new LoggingStopWatch();//... execute code here to be timedstopWatch.stop("example1", "custom message text");
• Allows parsing, analyzing and monitoring the logs.
3
![Page 5: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/5.jpg)
Features / Highlights of Perf4J
• A simple stop watch mechanism for concise timing statements.• A command line tool for generating aggregated statistics and
performance graphs from raw log files.• Custom log4j appenders to generate statistics and graphs in a
running application, with java.util.logging and logback support scheduled for subsequent releases.
• The ability to expose performance statistics as JMX attributes, and to send notifications when statistics exceed specified thresholds.
• A @Profiled annotation and a set of custom aspects that allow unobtrusive timing statements when coupled with an AOP framework such as AspectJ or Spring AOP.
4
![Page 6: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/6.jpg)
Timing using StopWatch
• Base class : LoggingStopWatch
• SubClass : Log4JStopWatch, CommonsLogStopWatch and Slf4JStopWatch
5
![Page 7: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/7.jpg)
Log Parsers: Statistics and Graphs
• Groups stop watch output by tag and by time slice
• Generating detailed statistics information• Time series graphs using the Google Chart API• LogParser reads from standard input thus
allowing it to get output generated in real time.– tail -f performance.log | java -jar perf4j-0.9.8.1.jar
6
![Page 8: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/8.jpg)
Sample for LogParser
7
![Page 9: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/9.jpg)
Integrating Directly With Log4J
• Set of custom log4j appenders
• Allows Perf4J to expose performance data as attributes on JMX MBeans, and to send JMX notifications.
• Provides graphing appenders that generate performance graphs which can be exposed through a web front-end using a Perf4J graphing servlet.
8
![Page 10: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/10.jpg)
sample log4j.xml – perf4j
9
![Page 11: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/11.jpg)
sample log4j.xml – log4j and perf4j
10
![Page 12: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/12.jpg)
Perf4J appender for JMX:
11
![Page 13: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/13.jpg)
@Profiled Annotation
• Reduces the "signal-to-noise" ratio of the code.• Allowing the method body to remain free of
StopWatch code.• Perf4J custom timing aspect can be enabled
with an aspect-oriented programming framework such as AspectJ or Spring AOP
• Minimal overhead.
12
![Page 14: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/14.jpg)
@Profiled Annotation - sample
@Profiled(tag = "dynamicTag_{$0}")
public void profiledExample(String tagSuffix) {
... business logic only here
//method body to remain free of StopWatch code
}
13
![Page 15: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/15.jpg)
Pitfalls and Best Practices
• Application monitoring - Fail to optimally deliver their intended benefits
• Either too much or not enough where it is required.
• Overhead
14
![Page 16: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/16.jpg)
Pitfalls and Best … cont
• When deciding which methods and code blocks to profile, focus on the big fish first.
15
![Page 17: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/17.jpg)
Pitfalls and Best … cont
• Perf4J is designed to offload performance analysis to a separate thread or process.
16
![Page 18: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/18.jpg)
Pitfalls and Best … cont
• Don’t forget the benefits of performance regression testing
17
![Page 19: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/19.jpg)
Pitfalls and Best … cont
• Take advantage of the @Profiled annotation and AspectJ’s load-time weaving to decide which methods should be timed at deployment time.
18
![Page 20: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/20.jpg)
Pitfalls and Best … cont
• Don’t forget about parts of your application that execute outside of the JVM
19
![Page 21: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/21.jpg)
Future Directions for Perf4J
• Methods to be profiled using a separate configuration file
• To time method executions without access to source code
20
![Page 22: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/22.jpg)
The End
5 minutes of question time
starts now!
![Page 23: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/23.jpg)
Questions
4 minutes left!
![Page 24: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/24.jpg)
Questions
3 minutes left!
![Page 25: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/25.jpg)
Questions
2 minutes left!
![Page 26: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/26.jpg)
Questions
1 minute left!
![Page 27: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/27.jpg)
Questions
30 seconds left!
![Page 28: Performance Analysis and Monitoring with Perf4j](https://reader033.vdocuments.site/reader033/viewer/2022052600/5580edd6d8b42aec5a8b517f/html5/thumbnails/28.jpg)
Questions
TIME IS UP!