Java in Flames

Netflix Technology Blog
15 min readintermediate
--
View Original

Overview

The article discusses the implementation of mixed-mode flame graphs for Java applications, enabled by the new JDK option -XX:+PreserveFramePointer. These flame graphs provide a comprehensive visualization of CPU usage, allowing developers to identify performance bottlenecks and CPU consumers that are often hidden from traditional profilers.

What You'll Learn

1

How to generate mixed-mode flame graphs for Java applications

2

Why using -XX:+PreserveFramePointer is essential for accurate profiling

3

How to interpret flame graphs to identify CPU bottlenecks

Prerequisites & Requirements

  • Understanding of Java performance profiling concepts
  • Familiarity with Linux perf_events and flame graph tools(optional)

Key Questions Answered

What is the purpose of mixed-mode flame graphs in Java?
Mixed-mode flame graphs visualize CPU usage across Java methods, system libraries, and kernel code, revealing CPU consumers that traditional profilers miss. This allows developers to identify performance issues and understand CPU consumption in a unified view.
How do you generate flame graphs for Java applications?
To generate flame graphs, install Linux perf_events, Java 8 update 60 or newer, perf-map-agent, and FlameGraph. Run Java with the -XX:+PreserveFramePointer option, then use perf to record CPU usage and generate the flame graph using the provided scripts.
What challenges exist with traditional Java profilers?
Traditional profilers either focus on Java methods or system code paths, missing crucial context. This limitation necessitated the use of both types of profilers, leading to incomplete insights into CPU usage, which mixed-mode flame graphs aim to resolve.
What are the implications of using -XX:+PreserveFramePointer?
Using the -XX:+PreserveFramePointer option can slightly decrease performance, costing between 0% and 3% extra CPU depending on the workload. This trade-off is necessary for accurate stack tracing in flame graphs.

Key Statistics & Figures

Performance cost of using -XX:+PreserveFramePointer
0% to 3%
This performance overhead varies depending on the specific workload being executed.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Backend
Java
Used for developing applications that can be profiled with mixed-mode flame graphs.
Tool
Linux Perf_events
A profiling tool used to capture CPU usage and generate flame graphs.
Tool
Perf-map-agent
A JVMTI agent that provides symbol translation for Java applications during profiling.
Tool
Flamegraph
A Perl-based tool for generating visual representations of profiling data.

Key Actionable Insights

1
Implement mixed-mode flame graphs in your Java applications to gain deeper insights into CPU usage.
These graphs can reveal hidden performance bottlenecks that traditional profilers overlook, enabling more effective optimization strategies.
2
Utilize the -XX:+PreserveFramePointer option during profiling to ensure accurate stack traces.
This option allows for better visibility into Java and system interactions, which is crucial for diagnosing performance issues.
3
Consider integrating perf-map-agent to automate symbol mapping for Java applications.
This tool simplifies the process of generating symbol files, which enhances the accuracy of flame graphs and reduces manual overhead.

Common Pitfalls

1
Many Java frames may be missing from flame graphs due to inlining and the nature of frame pointer profiling.
This occurs because the profiling method captures only the final executed code, potentially omitting important context. Developers should be aware of this limitation and consider adjusting inlining settings if necessary.

Related Concepts

Java Performance Profiling
Flame Graph Visualization Techniques
System And Jvm Profiling Tools