JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When Things Go Wrong
•
4 likes•1,812 views
Top 10 Causes for Java Issues in Production and What to Do When Things Go Wrong
JavaOne 2010.
Abstract: It's Friday evening and you hear the first rumble . . . one java node has become slightly unresponsive. You lookup the process, get a thread dump, and for good measure restart it at 8 p.m. Saturday afternoon is when you realize that other nodes have caught the flu and you get the ugly call from the customer. In a matter of hours, you're on that conference bridge with support groups of different packages and Java vendors and one of your uberarchitects. Yes, production instances are up and down, and restarting like there's no tomorrow. Here's an accumulated compendium of the op 10 things that can cause Java production heartburn and what to do when your Java production is on fire. And yes, please have your tools belt on.
Speaker(s):
Cliff Click, Azul Systems, Distinguished Engineer
SriSatish Ambati, Azul Systems, Performance Engineer
1 of 35
Download to read offline
More Related Content
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When Things Go Wrong
1. Top 10 Issues for
Java in Production
SriSatish Ambati
Cliff Click Jr.
Azul Systems, Inc
2. A Decade of
Java in Production
• A lot of hard-earned wisdom
• A lot of victories (quickly forgotten)
• A lot of endless pain points
• Usually the Pain Point is really
A Systems Issue
• It's Not Just the JVM (nor network, nor ...)
3. Tools of the Trade
• What the JVM is doing:
– dtrace, hprof, introscope, jconsole, visualvm,
yourkit, azul zvision
• Invasive JVM observation tools:
– bci, jvmti, jvmdi/pi agents, logging
• What the OS is doing:
– dtrace, oprofile, vtune
• What the network/disk is doing:
– ganglia, iostat, lsof, nagios, netstat
5. • Symptom
– Production monitoring can be very expensive
Staging environment does not repro issues
– Instrumented code changes cache profile
– MBeans are not cheap either!
• Solutions
– Pick the right axe for the problem!
– Avoid expensive heap walks
– Finish task then increment perf counters
– Asynchronous logging, jconsole, azul zvision
10 - Instrumentation is
Not Cheap
6. 9 - Leaks
• Symptom
– App consumes all the memory you got
– Live Heap trend is a ramping sawtooth
– Then slows, then throws OutOfMemory
• Tools
– yourkit, hprof, eclipse mat, jconsole,
jhat, jps, visualvm, azul zvision
• Theory
– Allocated vs Live Objects, vm memory, Perm Gen
– Finalizers, ClassLoaders, ThreadLocal
13. • Symptom
– Multi-node scale-out does not scale linearly
– Time in both CPU and I/O (serialization costs)
• Tools
–Cpu profiling, I/O profiling
• Solution
– All serialization libraries are not equal!
– Pick a high performance serialization library or
roll-your-own
– Avro, kryo, protocol-buffers, thrift
8 – I/O: Serialization
14. • Symptom
– Application hangs or remote call fails after awhile
– “Too many open File Descriptors”, “Cursors”
– Inconsistent response times
• Tools
– nagios, pkg, rpm info, ulimit, yum
• Solutions
– Check for “new” OS patches, user & process limits,
network & semaphore configurations
– Close all I/O streams
– Maybe you are I/O bound!
8 – I/O: Limits, Tuning
15. • Symptoms
– Socket.create/close takes too long
– JRMP timeouts, long JDBC calls
– Running out of file descriptors, cursors, disk
• Tools
– dbms tools, du, iostat, gmon, lsof, netstat
• Workaround
– Check all O/S patches, sysctl flags,
run ping/telnet test
– Check & set SO_LINGER, TCP_LINGER2
8 – I/O: Sockets, Files, DB
17. • Symptoms
– Adding users / threads / CPUs causes app slow down
(less throughput, worse response)
– High lock acquire times & contention
– Race conditions, deadlock, I/O under lock
• Tools
– d-trace, lockstat, azul zvision
• Solution
– Use non-blocking Collections
– Striping locks, reducing hold times, no I/O
7 – Locks & synchronized
18. Example: IBM Visual Analyzer
(j.u.c view in eclipse)
Zillion threads acquiring same lock
j.u.c.ConcurrentLock is still a lock!
Need a non-blocking collection
(or stripe lock or lower hold times, etc)
19. Example: zvision
Hot lock is usually 10x to 100x
more acquire time than next lock..
Look for rapidly growing acquire times!
21. • Symptom
– Time “compiling”
– Time in the Interpreter
• Tools
– -XX:+PrintCompilation, cpu profiler
– Find endlessly-recompiling method
• Workaround
– Exclude using .hotspot_compiler file
• Root cause: It's a JVM Bug! File a bug report!
6 – Endless Compilation
22. • Symptom
– Application spends time in j.l.T.fillInStackTrace()
• Tools
– Cpu profiler, azul zvision
– Thread dumps (repeated kill -3, zvision)
– Track caller/callee to find throw'r
• Not all exceptions appear in log files
• Solution
– Don't Throw, alternate return value (e.g. null)
5 – Endless Exceptions
23. • Related
– Exception paths are typically failure paths
– JVMs do not to optimize them much
– Often found when a server collapses
5 – Endless Exceptions
24. • Symptom
– Performance degrades over time
– Inducing a “Full GC” makes problem go away
– Lots of free memory but in tiny fragments
• Tools
– GC logging flags, e.g. for CMS
-XX:PrintFLSStatistics=2
-XX:+PrintCMSInitiationStatistics
4 - Fragmentation
25. • Tools
– “Fragger” www.azulsystems.com/resources
• Tiny cpu cost, low memory cost
• Frag's heap in 60sec like an hour in production
• Get FullGC cycles at dev's desk
• Solution
– Upgrade to latest CMS (CR:6631166)
– Azul Zing & Gen Pauseless GC
– Pooling similar sized/aged objects
• (really hard to get right!)
4 - Fragmentation
26. • Symptom
– Entropy(gc) == number_of_gc_flags
• Too many free parameters
• 64-bit/large heap size is not a solution
– Constant 40-60% CPU utilization by GC
– Scheduled reboot before full-GC
– Full time Engineer working GC flags;
• Workarounds
– Ask JVM Vendor to give 1 flag solution
– G1 GC, Azul’s Zing GPGC
3 – GC Tuning
30. • Symptom
– Different nodes have different configurations,
different stack components, versions
– classpath has dist/*, -verbose:class
– subtle hard to reproduce issues
• Solution
– Method. Version Control.
– Good ol’ fashioned rigor
1 – Versionitis
When ears wage class wars with jars
“It can only be attributable to human error” - HAL
31. • Runs fine as load Ramps Up
– At peak load, system is unstable
– Slightly above peak: Collapse!
• Heavy load triggers exception (e.g. timeout)
• Exception path is slow already (e.g. logging)
• Transaction retried (so more work yet again)
• So NEXT transaction times-out
• Soon all time spent throwing & logging exceptions
• No forward progress
0 – Collapse Under Load
(pick any 3 above!)
33. References:
Java.util.concurrent lock profiling
http://infoq.com/jucprofiler
Java serialization benchmarks
http://code.google.com/p/thrift-protobuf-compare/wiki/BenchmarkingV2
Memory profiling with yourkit
http://yourkit.com
Tuning gc
http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html
http://blog.codecentric.de/en/2010/01/
java-outofmemoryerror-a-tragedy-in-seven-acts/
Cliff Click's High Scale lib, Non-Blocking HashMap
http://sourceforge.net/projects/high-scale-lib/
Q & A
(& Refs 1 of 2)
34. References:
Memory Leak
http://deusch.org/blog/?p=9
Handy list of jvm options
http://blogs.sun.com/watt/resource/jvm-options-list.html
Fragger (with source code)
http://www.azulsystems.com/resources
Garbage Collection: Algorithms for Automatic Dynamic Memory
Management, Richard Jones, Rafael D Lins
Q & A
(& Refs 2 of 2)
35. Backup slide–
Fragmentation
• Works well for hours at
300-400MB
– Same workload
• Suddenly haywire
– Promotion
• Too frequently
– Back to back FullGCs
– May not all be
completing.