Maximize Java Performance by using YOURKIT with uPortal development - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Maximize Java Performance by using YOURKIT with uPortal development

Description:

... leak in java? Java Memory leak. Allocated. Reachable. Live ... Loitered objects are reachable, but they are not live. 13. Most common memory leak causes ... – PowerPoint PPT presentation

Number of Views:298
Avg rating:3.0/5.0
Slides: 24
Provided by: williamgt
Category:

less

Transcript and Presenter's Notes

Title: Maximize Java Performance by using YOURKIT with uPortal development


1
Maximize Java Performance by using YOURKIT with
uPortal development
  • Faizan Ahmed Sr. Application Developer

2
Overview
  • Why memory related issues are problem?
  • Introduction to YourKit.
  • Some terms
  • What is Java Memory Leak?
  • Find and resolve memory leak (demo)
  • Some code tips.

3
Why memory related issues can be performance
problem?
  • Memory-related issues affect execution speed and
    reliability of application.

4
Getting started with YourKit
  • Download and extract the zip file.
  • Set PATH to dll
  • ltYJP Homegt\bin\win32
  • Check installation
  • java -Xrunyjpagenthelp
  • IDE configuration
  • Plug-in installation
  • Enable action group profile
  • Windows customize perspective commands
  • Agent configuration
  • -agentlibyjpagent

5
Snapshots
  • YourKit investigative model is based upon
    snapshots which capture the state of the
    application at specific points in time.

6
Dynamic Nature of a RootSet
  • Root Set is a set of foundational object
    references within your application
  • public class uPortal
  • private static uPortal portal null
  • public static void main(String args)
  • portal new uPortal()
  • portal.method1()

Root Set uPortal portal String args
7
Dynamic Nature of a RootSet
  • Private void method1
  • FooObject fooObject new FooObject()
  • ..

Root Set uPortal portal String args FooObject
fooObject
8
Dynamic Nature of a RootSet
  • public class uPortal
  • private static uPortal portal null
  • public static void main(String args)
  • portal new uPortal()
  • portal.method1()
  • .

Root Set uPortal portal String args
9
What is Memory leak in Java?
  • Occurs when objects that have outlived their
    usefulness to the application remain within the
    heap through successive garbage collections

10
What is a memory leak in Java?
  • We can extend the set of object states to three
  • Allocated
  • Exists within the JVMs heap
  • Reachable
  • A path exists (directly or indirectly) from a
    member of the root set, through a sequence of
    references to that object.
  • Live
  • From the intent of the application design the
    program will use the object.

11
What is memory leak in java?
Handled by JVM
Allocated
Reachable
Live
Java Memory leak
12
What are loitered Objects?
  • Loitered objects are reachable, but they are not
    live.

13
Most common memory leak causes
  • Failure to remove Stale Object References from
    Data Structures.
  • Lingering Transitional references.
  • A reference to a short-term object is used
    transiently by a long-term object but the
    long-term object does not clear the reference
    when its done with it.

14
Preparing for your investigation
  • Have a firm conceptual grasp of the architecture
    of the application you are about to analyze.
  • An attitude that you can find, and resolve, the
    underlying problem.

15
How to find leaked Objects?
  • By Comparing snapshots.

16
How to find leaked Objects?
  • More Disciplined approach.
  • Establish a hypothesis (around the expected leak
    area) (What you expect to see).
  • Design and run an experiment to prove your
    hypothesis (a use case).
  • Compare the experimental results against your
    hypothesis.
  • Resolve the differences. (if any)

17
Loitering Objects Recap
  • Objects that remain within the heap past their
    useful life to the application.
  • To eliminate loitering objects from your
    application, you must first
  • Identify which objects (if any) are loitering
    within your application.
  • Determine why those objects remain reachable
    beyond their designed lifetime.

18
Some Tips
  • Reference variable scope
  • Dont be concerned about assignments to
    method-based reference variables within methods
    of short execution time.
  • Be attentive of assignments to class-based and
    object-based reference variables, and
    method-based reference variables within methods
    of long execution time.

19
Some Tips
  • As a general rule do not use finalizer.
  • Where appropriate to your design, use the method
    attributes
  • static
  • final
  • private

20
Some Tips (Continued)
  • Try to keep critical methods to a few statements
    in length, and declare them static, final or
    private.
  • In critical loops, avoid method calls within the
    loop termination test..
  • Example on next page

21
Some Tips (Continued)
  • Replace
  • for (int i0 i lt collection.size() i)
  • .
  • With
  • for(int i0, ncollection.size() iltn i)
  • ---

22
Some Tips (Continued)
  • If you cache some objects you better have a
    working caching strategy and remove objects
    from cache at some point.
  • No user session really means 0 user session in
    the system.

23
Questions Comments !
Write a Comment
User Comments (0)
About PowerShow.com