Java Performance Debugging
Few Questions to Consider
•   What is expected throughput
•   What is expected latency
•   Maximum No. of concurrent users/tasks
•   Expected Throughput/latency at max users
•   Worst case latency
•   Tolerable GC latency
Bottlenecks
•   Memory
•   CPU
•   Disk I/O
•   Network I/O
Memory (RAM)
•   -Xmx too low
•   Process leaking memory (et tu java!)
•   Insufficient DirectBuffers
•   Insufficient PermGen space
•   Page thrashing
Memory (Contd.)
• Run –XX:+HeapDumpOnOutOfMemoryError.
  Check .hprof files in working directory or –
  XX:HeapDumpPath

• jmap –histo<pid>
Memory (contd.)



• High si/so coinciding with low ‘free’ memory
  implies page thrashing
Other OutOfMemory Errors
• Incorrect PermGen size –XXMaxPermSize
  –   java.lang.OutOfMemoryError: PermGen space

  – jstat -gc<pid>
  – Can monitory ‘PU’ vs ‘PGCMX’ from jstat -
    gccapacity
• Incorrect Direct Buffer limit -
  XX:MaxDirectMemorySize
  –   java.lang.OutOfMemoryError: Direct buffer memory
CPU
• Check Garbage collector stats
  – Jstat –gc<pid>
• Investigate using – JMX, TOP
  – Using TOP get the thread ID
  – Thread Dump using ‘kill -3’ or ‘jstack’
  – Search Hex thread id in thread dump
Disk I/O
• Iostat %iowait<interval><samples>

• High %iowait indicates I/O bottleneck

• If java process is causing high I/O, check the
  thread dump
Java Heap Structure
Garbage Collector Choice
• Serial GC (Never use this!)
  – -XX:+UseSerialGC
• Parallel GC (High Throughput) – Use in non-
  interactive jobs which can tolerate pause of 1-
  2 sec
  – -XX:+UseParallelGC –XX:+UseParallelOldGC
• CMS (Low Latency) – Good for webapps and
  interactive processes
  – -XX:+UseConcMarkSweepGC

Java performance

  • 1.
  • 2.
    Few Questions toConsider • What is expected throughput • What is expected latency • Maximum No. of concurrent users/tasks • Expected Throughput/latency at max users • Worst case latency • Tolerable GC latency
  • 3.
    Bottlenecks • Memory • CPU • Disk I/O • Network I/O
  • 4.
    Memory (RAM) • -Xmx too low • Process leaking memory (et tu java!) • Insufficient DirectBuffers • Insufficient PermGen space • Page thrashing
  • 5.
    Memory (Contd.) • Run–XX:+HeapDumpOnOutOfMemoryError. Check .hprof files in working directory or – XX:HeapDumpPath • jmap –histo<pid>
  • 6.
    Memory (contd.) • Highsi/so coinciding with low ‘free’ memory implies page thrashing
  • 7.
    Other OutOfMemory Errors •Incorrect PermGen size –XXMaxPermSize – java.lang.OutOfMemoryError: PermGen space – jstat -gc<pid> – Can monitory ‘PU’ vs ‘PGCMX’ from jstat - gccapacity • Incorrect Direct Buffer limit - XX:MaxDirectMemorySize – java.lang.OutOfMemoryError: Direct buffer memory
  • 8.
    CPU • Check Garbagecollector stats – Jstat –gc<pid> • Investigate using – JMX, TOP – Using TOP get the thread ID – Thread Dump using ‘kill -3’ or ‘jstack’ – Search Hex thread id in thread dump
  • 9.
    Disk I/O • Iostat%iowait<interval><samples> • High %iowait indicates I/O bottleneck • If java process is causing high I/O, check the thread dump
  • 10.
  • 11.
    Garbage Collector Choice •Serial GC (Never use this!) – -XX:+UseSerialGC • Parallel GC (High Throughput) – Use in non- interactive jobs which can tolerate pause of 1- 2 sec – -XX:+UseParallelGC –XX:+UseParallelOldGC • CMS (Low Latency) – Good for webapps and interactive processes – -XX:+UseConcMarkSweepGC