Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java Performance Tuning - A top down approach

DZone's Guide to

Java Performance Tuning - A top down approach

Free Resource

Download our Introduction to API Performance Testing and learn why testing your API is just as important as testing your website, and how to start today.

Symptoms

  • Memory
  • CPU
  • I/O
    • Devices
    • Network
Indicators - Windows undefined

Indicators - Linux

  • Sar, top, dstat, etc.
undefined

Jumping Board - JConsole

  • Study the JVM Args
  • Heap Usage should follow a saw tooth pattern denoting there is no leak
  • There should not be any anonymous threads like ‘Thread 1’
  • Look for creation of dynamic classes in large numbers
  • CPU Usage

Heap ?

  • Heap is utilized throughout the Object Life-cycle starting from new object creation, variable references, dereferences by variables going out of scope and finally till Garbage Collection
  • Object references can be represented in a tree fashion as we do deep references and the cumulative size retained at each level can be determined using offline utilities
  • There can multiple top level objects in the current program flow context that can retain individual object tree
  • parent node should be shallow in size such that it does not retain memory compared to its child nodes
  • When there is a large difference in retained size between parent and child node, i.e drops, there is a possibility of memory leak

Deep Dive – Heap Analysis

Online
  • VisualVM, JRockit, IBM Health Center
  • Profilers 
Offline
  • IBM Heap Analyzer
  • Eclipse MAT

Deep Dive – Memory Leaks

undefined

CPU?

  • Thread dumps provides  thread status, monitors, number of threads waiting for the monitor and call stack of methods
  • Comparing thread dumps taken at frequent intervals can reveal as to which tasks (call stack) are being performed across thread dumps
  • Online profiling tools can provide hotspot methods
  • Snapshots can provide thread wise call tree, along with response time

Deep Dive – Threads & Call Stack

Online
  • VisualVM, JRockit, IBM Health Center
  • Profilers 
Offline
  • IBM Thread and Monitor Dump Analyzer

Deep Dive – Threads & Call Stack

undefined

undefined

I/O?

  • Study the read, writes and response time of the Java process and identify the device that is heavily utilized or not responding
  • Study the network traffic in terms of number of connections, bytes sent / received and transfer rate

Deep Dive - I/O

  • Based on the heavy reads / writes look for input and output streams without buffering, multiple reads of same resources, unnecessary serialization, etc
  • Re-use of connection, file transfer in uncompressed form, releasing network resources (such as result set, statement and connection), etc

Performance Case Study - Heap

undefined

Performance Case Study - CPU

undefined

Best Practices

  • Understand your application environment such as firewall, layers (web, app & db), third party data providers if any
  • Use offline tools and less intrusive tools in production environments
  • Look for tools provided by the JVM vendor or the Application Server vendor
  • Use JMeter for recreating production scenario in your environment

Find scaling and performance issues before your customers do with our Introduction to High-Capacity Load Testing guide.

Topics:
java ,performance

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}