Java Performance Tuning (Full Presentation) by Ender
Java Performance Tuning (Full Presentation) by Ender
Java Performance Tuning (Full Presentation) by Ender
koders.co
WHAT YOU WILL LEARN ?
You WILL LEARN:
• Performance Specialists
Performance Tuning Steps
Monitoring
Performance Tuning Steps
Profiling
Performance Tuning Steps
Tuning
JVM Overview &
2 INTERNALS
koders.co
Objectives
• JVM Runtime & Architecture
• VM Life Cycle
• Class Loading
JAVA PROGRAMMING LANGUAGE
• Object oriented, Garbage collected*
• Class based
–DAVID WHEELER
JVM Overvıew
• JVM: Java Virtual Machine
–JOEL SPOLSKY
HOTSPOT VM ARCHITECTURE
HOTSPOT VM ARCHITECTURE
COMMAND LINE OPTIONS
• Standard: Required by JVM specification, standard
on all implementations (-server, -classpath)
• Responsiveness
• Throughput
• Memory Footprint
• Startup Time
• Scalability
RESPONSIVENESS
• Ability of a system to complete assigned tasks within
a given time
1.Monitoring
2.Profiling
3.Tuning
Performance Monitoring
• Non-intrusively collecting and observing performance
data
• JVM ergonomics
GC PERFORMANCE METRICS
• There are mainly 3 ways to measure GC
performance:
• Throughput
• Responsiveness
• Memory footprint
FOCUS: Throughput
• Throughput is secondary
GC ALGORITHMS
• Serial vs Parallel
• Stop-the-world vs Concurrent
• Parallel Collector
• G1 Collector
SERIAL / Parallel Collector
SERIAL COllector
• Serial collection for both young and old generations
• Suitable for:
• Young (-XX+UseParallelGC)
• Throughput is important
• Suitable for
• Focus: Responsiveness
• Concurrent collector
CMS COLLECTOR
g1 Collector
g1 Collector [REGIONS]
g1: YOUNG GC
g1: YOUNG GC
g1: YOUNG GC [end]
g1: PHASES
1. Initial Mark (stop-the world)
3. Concurrent marking
4. Remark (stop-the-world)
* Copying (stop-the-world)
g1: PHASES [INITIAL MARK]
g1: PHASES [Concurrent mark]
g1: PHASES [REMARK]
g1: PHASES [COPYING/CLEANUP]
g1: PHASES [AFTER COPYING]
COMMAND LINE
6 Monitoring
koders.co
Objectıves
• Using JVM command line tools
• Monitor JVMs
• JIT compilation
• Data of interest
• jps
• jmcd
• jstat
JIT COMPILATION
• JIT compiler: optimizer, just in-time compiler
• jstat
• Data of interest
• -XX:CompileCommand=exclude,java/lang/String,toString
Monitoring OS
7 Performance
koders.co
Objectıves
• Monitor CPU usage
• Monitor processes
• On Linux (+Windows)
Terminology
• CPU utilization
• top • prstat
• htop • gnome-system-monitor
• vmstat
MONITORING MEMORY
• Key points
• Memory footprint
• free
• vmstat
MONITORING DISK I/O
• Key points
• iostat
• lsof
• iotop
MONITORING NETWORK I/O
• Key points
• Connection count
• netstat • iftop
• iptraf • monitorix
• tcpdump
USING
8 Visual Tools
koders.co
Objectıves
• Monitor Java applications using visual tools:
• JConsole
• VisualVM
• Mission Control
JConsole
• Ships with JVM
• CPU, Memory,
Classloading, Threads
• Demo
VISUALVM
• Graphical monitoring,
profiling, troubleshooting
tool
• Demo
MISSION CONTROL
• Comprehensive
application
• Better UI
• Monitor,
operate,manage, profile
Java applications
• Demo
JMX - MANAGED BEANS
• JMX: Java Management Extensions
• JVisual VM
• Demo
VISUALVM
• Demo
10 Profiling
Performance Issues
koders.co
Objectives
• Profiling Java applications to troubleshoot and
optimize
• Visual VM
• Flight Recorder
• Overallocation of objects
• Parameter: -XX:+UseSerialGC
SERIAL COLLECTOR: TIPS
• Not suitable for applications with high performance
requirements
• Parameters:
• Parameter: -XX:+ConcMarkSweepGC
CMS COLLECTOR: GOOD TO KNOW
• CMS targets responsiveness and runs concurrently.
And it doesn’t come for free.
• Memory fragmentation
• Parameter: -XX:+UseG1GC
• Usage of finalizers
• Allocation
• Initialization
• non-exceptional cases
• flow control
THREADS
• Avoid excessive use of synchronized
• As short as possible
koders.co