IMLC.ME

Java Performance Tuning Cheatsheet

GC

Enable GC Log
 -Xlog:gc*:file={file-path}
Print GC info
 jstat -gc -t 11656 10000 30

jstat - Java Virtual Machine Statistics MonitoringTool

Analysis

Universal JVM GC analyzer - Java Garbage collection log analysis made easy

Thread

thread — Arthas 3.5.0 documentation

jstack - Stack Trace

The jstack Utility

`-Xlog:thread+os:file=/tmp/threads.log`

Thread Pool

Java线程池实现原理及其在美团业务中的实践 - 美团技术团队

Tuning the Size of Your Thread Pool

Thread pool settings - IBM

Analysis

jstack.review - Java Thread Dump Analyzer

Smart Java thread dump analyzer - thread dump analysis in seconds

Heap

heapdump — Arthas 3.5.0 documentation

The jmap Utility

jhsdb jstack

Analyze memory snapshots | IntelliJ IDEA

Analyze objects in the JVM heap | IntelliJ IDEA

Automatically heap dump when OOM
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=<file-or-dir-path>
Analysis

Eclipse Memory Analyzer Open Source Project | The Eclipse Foundation VisualVM: Home jhat - Java Heap Analysis Tool

References

Different Ways to Capture Java Heap Dumps | Baeldung

Non-Heap/Director Memory

Native Memory Tracking

CPU

GitHub - uber-common/jvm-profiler: JVM Profiler Sending Metrics to Kafka, Console Output or Custom Reporter

Profiling tools | IntelliJ IDEA

GitHub - jvm-profiling-tools/async-profiler: Sampling CPU and HEAP profiler for Java featuring AsyncGetCallTrace + perf_events

Java VisualVM - Profiling Applications

HPROF: A Heap/CPU Profiling Tool

profiler — Arthas 3.5.0 文档

Frame Graph

火焰图/差分火焰图

Reference

JVM CPU Profiler技术原理及源码深度解析 - 美团技术团队

A Guide to Java Profilers | Baeldung

Stack Trace

Analyze external stack traces | IntelliJ IDEA

JVM

jhsdb jinfo

jvm — Arthas 3.5.0 documentation

Monitoring

Micrometer Application Monitoring

Home — Dropwizard

Micrometer: Spring Boot 2’s new application metrics collector

Logging
  • Enable Async Logging - Chapter 4: Appenders - AsyncAppender
  • Using trace id for every request
  • Using global trace id for e2e trace
  • Using sampling/throttling/rate limiting to limit the performance impact
End-to-end tracing

Jaeger: open source, end-to-end distributed tracing

Dynamic Tracing

Java动态追踪技术探究 - 美团技术团队

trace — Arthas 3.5.0 documentation

Introduction - Dynamic Tracing Guide

Dynamic Tracing and Instrumentation

GitHub - btraceio/btrace: BTrace - a safe, dynamic tracing tool for the Java platform

GitHub - cglib/cglib: cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

Code Performance

monitor/watch/trace in Arthas

monitor — Arthas 3.5.0 documentation

Inspection

JConsole

TCPDUMP/LIBPCAP public repository

Wireshark · Go Deep.

Visualization

Grafana

Splunk

Kibana

Excel

echart

InfluxDB: Purpose-Built Open Source Time Series Database | InfluxData

Benchmarking

JMH

jmh/JMHSample_13_RunToRun.java at master · openjdk/jmh · GitHub

GitHub - artyushov/idea-jmh-plugin: Plugin for Itellij IDEA to make benchmarking with JMH easier.

Google Caliper

GitHub - google/caliper: Micro-benchmarking library for Java

Mocking

Mock Cassandra

GitHub - datastax/simulacron: Simulacron - An Apache Cassandra® Native Protocol Server Simulator

In-Memory Database

https://www.h2database.com/html/main.html

JIT Optimization

Java JIT 性能调优 - 开发者头条

JIT 编译器如何优化代码

基本功 | Java即时编译器原理解析及实践 - 美团技术团队

Java on Steroids: 5 Super Useful JIT Optimization Techniques | OverOps

Performance Improvements via JIT Optimization | by Malith Jayasinghe | Medium

Just-in-time compilation - Wikipedia

Kubernetes Optimization

GitHub - kubernetes-sigs/metrics-server: Cluster-wide aggregator of resource usage data.

Prometheus - Monitoring system & time series database

Kubernetes Monitoring, Application Debug Platform | Pixie

Istio / Visualizing Metrics with Grafana

GitHub - google/cadvisor: Analyzes resource usage and performance characteristics of running containers.

container_cpu_cfs_throttled_seconds_total

Linux Performance

USE Method: Linux Performance Checklist

CPU
Disk Usage
Memory Usage
Network IO Usage
File Descriptor

Network

ping
traceroute
iperf

Statistic

Avoid using average!! It lies!!
TP-based

Percentile - Wikipedia

Bucket

How to visualize Prometheus histograms in Grafana | Grafana Labs https://grafana.com/docs/grafana/latest/getting-started/intro-histograms/

Time-Based