http://osama-oransa.blogspot.com/
 Introduction
 Basic Java Concepts
◦ Concurrency
◦ Memory Management
 Java Profiler Tools
◦ NetBeans Profiler
◦ JProfil...
 Performance is one of the NFRs.
 Usually you have SLA for each transaction.
 2 types of performance issues :
◦ Perform...
 Problem Definition (UC, Scenario, Conditions,
User, ..etc…)
 Gather Information
 Try to replicate (if possible)
 Get ...
 Better if :
◦ Relay on tools output.
◦ Less dependant on personal experience.
◦ Concrete (not abstract)
◦ Always compara...
 Hardware
◦ CPU
◦ Network
◦ Memory
◦ Storage
 Software
◦ Operating System
◦ Libraries, Drivers and Utilities.
◦ Applicat...
 CPU :
◦ Detect root cause (anti-virus!)
◦ Change algorithm
◦ Increase CPU power.
 Network :
◦ Detect root cause (OS upd...
 Good but sometimes you can consider:
◦ CPU :
 Use MT.
 Change workflow.
◦ Memory :
 Utilize more memory in caching.
...
 Google it.
 Continuous follow-up is essential , as new
tips always come:
◦ Use StringBuffer rather than the string
conc...
 Vector, Stack, Hashtable are deprecated
 For single threaded use :
◦ ArrayList
◦ Deque
◦ HashMap
 For MT use : (a lot ...
 Concurrency
 Memory Management
 Has a self-contained execution environment.
 A process generally has a complete, private
set of basic run-time resource...
 As simple as :
Process pb = new
ProcessBuilder("myCommand",
"myArg").start();
 But can be more complex by defining the
...
 Both processes and threads provide an
execution environment, but creating a new
thread requires fewer resources than cre...
 Every application has at least one thread — or
several, if you count "system" threads ( like
memory management ).
 But ...
 Using the Interface or extending the Class :
public class HelloRunnable implements Runnable {
public void run() {
System...
 Each object in Java is associated with a
monitor, which a thread can lock or unlock.
 Only one thread at a time may hol...
 A synchronized method automatically
performs a lock action when it is invoked;
◦ Its body is not executed until the lock...
 Use Generational Collection
◦ Memory is divided into generations, that is,
separate pools holding objects of different a...
 A garbage collector is responsible for
◦ Allocating memory
◦ Ensuring that any referenced objects remain in
memory
◦ Rec...
 Serial versus Parallel
◦ When parallel collection is used, the task of garbage
collection is split into parts and those ...
 Compacting versus Non-compacting
◦ Make it easy and fast to allocate a new object at
the first free location (One pointe...
 Most objects are initially allocated in Eden.
◦ A few large objects may be allocated directly in the
old generation
 Th...
 Both young and old collections are done
serially (using a single CPU), in a stop-the
world fashion.
 Application execut...
 The collector then performs sliding
compaction, sliding the live objects towards
the beginning of the old generation spa...
 Non-compacting..
-Xms<min> //initial heap size
-Xmx<max> //max heap size
-XX:PermSize= //initial perm size
-XX:MaxPermSize= //max perm size...
 -verbose:gc
 [GC 325816K->83372K(776768K), 0.2454258 secs]
[Full GC 267628K->83769K(776768K), 1.8479984 secs]
 [GC (1)...
 Variant :
◦ Java heap space / Requested array size exceeds VM limit
= heap size issue
◦ PermGen space = no memory for cr...
 NetBeans Profiler
 Eclipse : TPTP, MAT, Profiling, JVMMonitor,
etc..
 Java : Jconsole, jstat
 JProfiler
 AppDynamics...
 Location: Local or Remote.
 GUI: Online or Offline.
 Time: Attach or started for profiling.
 CPU: Sampled or Instrume...
 We will try 3 profilers:
◦ NetBeans Profiler
◦ JProfiler
◦ Eclipse TPTP
 Detecting hotspots
 Blocking Threads
 Heap is growing …
 Easy actually it is the Same way 
 Attach to the running server …
 Add triggers to define what to record and to
save the snapshots..
 The session is added to configuration file
with “id” example :
◦ <session id="119"
◦ ….
◦ </session>
 Now in run comman...
 Same everything 
 For More information refer to Java EE 7
performance tuning and optimization book.
 The book is published by Packt Publi...
 http://www.oracle.com/technetwork/java/javase
/memorymanagement-whitepaper-150215.pdf
 http://docs.oracle.com/javase/sp...
 Introduction
 Basic Java Concepts
◦ Concurrency
◦ Memory Management
 Java Profiler Tools
◦ NetBeans Profiler
◦ JProfil...
http://osama-oransa.blogspot.com/
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
Upcoming SlideShare
Loading in...5
×

Profiler Guided Java Performance Tuning

1,567

Published on

For More information, refer to Java EE 7 performance tuning and optimization book:

The book is published by Packt Publishing:
http://www.packtpub.com/java-ee-7-performance-tuning-and-optimization/book

Published in: Software, Technology
2 Comments
1 Like
Statistics
Notes
  • That's good question, consider the overhead related to create the exception object and fill it with stacktrace while all what you need is just return a flag from the stack... You can do quick sample and measure the performance.. also find more details in the book itself. Thanks...
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Why Don’t use exception to return flag?.... can Please you tell me what is the reason
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,567
On Slideshare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
58
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Profiler Guided Java Performance Tuning

  1. 1. http://osama-oransa.blogspot.com/
  2. 2.  Introduction  Basic Java Concepts ◦ Concurrency ◦ Memory Management  Java Profiler Tools ◦ NetBeans Profiler ◦ JProfiler ◦ Eclipse TPTP  Questions
  3. 3.  Performance is one of the NFRs.  Usually you have SLA for each transaction.  2 types of performance issues : ◦ Performance Testing Results  In Dev or Test environment. ◦ Production Performance Issues  Difficult to handle.
  4. 4.  Problem Definition (UC, Scenario, Conditions, User, ..etc…)  Gather Information  Try to replicate (if possible)  Get all tools ready to use.  Build your plan: ◦ Analyze Tools output. ◦ Code Inspection ◦ Potential fixes. (Google it …) ◦ Re-test.
  5. 5.  Better if : ◦ Relay on tools output. ◦ Less dependant on personal experience. ◦ Concrete (not abstract) ◦ Always comparative. ◦ Quick POC ◦ Proven from Google   Better if not: ◦ Trial and error approach. ◦ Optimize as you go.
  6. 6.  Hardware ◦ CPU ◦ Network ◦ Memory ◦ Storage  Software ◦ Operating System ◦ Libraries, Drivers and Utilities. ◦ Application
  7. 7.  CPU : ◦ Detect root cause (anti-virus!) ◦ Change algorithm ◦ Increase CPU power.  Network : ◦ Detect root cause (OS updates!) ◦ Change architecture.  Memory : ◦ Root cause (memory leakage) ◦ add more memory, re-structure caching.  Storage : ◦ Add storage, free more space (archive) , etc.
  8. 8.  Good but sometimes you can consider: ◦ CPU :  Use MT.  Change workflow. ◦ Memory :  Utilize more memory in caching.  Change architecture.
  9. 9.  Google it.  Continuous follow-up is essential , as new tips always come: ◦ Use StringBuffer rather than the string concatenation operator (+). ◦ Use primitive data types instead of objects. ◦ Use short-circuit boolean operators whenever possible. ◦ Flatten objects as much as possible. ◦ Use the clone() method to avoid calling any constructors. ◦ Don’t use exception to return flag.
  10. 10.  Vector, Stack, Hashtable are deprecated  For single threaded use : ◦ ArrayList ◦ Deque ◦ HashMap  For MT use : (a lot of other alternatives) ◦ CopyOnWriteArrayList ◦ ConcurrentLinkedDeque ◦ ConcurrentHashMap
  11. 11.  Concurrency  Memory Management
  12. 12.  Has a self-contained execution environment.  A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.  Most operating systems support Inter Process Communication (IPC) resources, such as pipes and sockets  Most implementations of the Java virtual machine run as a single process.  A Java application can create additional processes using a ProcessBuilder object.
  13. 13.  As simple as : Process pb = new ProcessBuilder("myCommand", "myArg").start();  But can be more complex by defining the Input, Output , Error streams or inherit them using: pb.inheritIO() public Process start() throws IOException
  14. 14.  Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process.  Threads exist within a process — every process has at least one.  Threads share the process's resources, including memory and open files.  This makes for efficient, but potentially problematic, communication.
  15. 15.  Every application has at least one thread — or several, if you count "system" threads ( like memory management ).  But from the application programmer's point of view, you start with just one thread, called the main thread.  This thread has the ability to create additional threads.
  16. 16.  Using the Interface or extending the Class : public class HelloRunnable implements Runnable { public void run() { System.out.println("Hello!"); } public static void main(String args[]) { (new Thread(new HelloRunnable())).start(); } }
  17. 17.  Each object in Java is associated with a monitor, which a thread can lock or unlock.  Only one thread at a time may hold a lock on a monitor.  A synchronized statement : ◦ It then attempts to perform a lock action on that object's monitor and does not proceed further until the lock action has successfully.
  18. 18.  A synchronized method automatically performs a lock action when it is invoked; ◦ Its body is not executed until the lock action has successfully completed. ◦ If the method is an instance method :  It locks the monitor associated with the instance for which it was invoked (this). ◦ If the method is static :  It locks the monitor associated with the Class object that represents the class in which the method is defined.
  19. 19.  Use Generational Collection ◦ Memory is divided into generations, that is, separate pools holding objects of different ages.
  20. 20.  A garbage collector is responsible for ◦ Allocating memory ◦ Ensuring that any referenced objects remain in memory ◦ Recovering memory used by objects that are no longer reachable from references in executing code.
  21. 21.  Serial versus Parallel ◦ When parallel collection is used, the task of garbage collection is split into parts and those subparts are executed simultaneously, on different CPUs.  Concurrent versus Stop-the-world ◦ Concurrent need extra care, as it is operating over objects that might be updated at the same time by the application. ◦ Adds some overhead and requires a larger heap size. ◦ Stop-the-world garbage collection is simpler since the heap is frozen and objects are not changing during the collection. ◦ It may be undesirable for some applications to be paused.
  22. 22.  Compacting versus Non-compacting ◦ Make it easy and fast to allocate a new object at the first free location (One pointer is enough) ◦ Non-compacting collector releases the space utilized by garbage objects in-place. ◦ Faster completion of garbage collection, but the drawback is potential fragmentation. (Need array of pointers) ◦ In general, it is more expensive to allocate from a heap with in-place deallocation than from a compacted heap.
  23. 23.  Most objects are initially allocated in Eden. ◦ A few large objects may be allocated directly in the old generation  The survivor spaces hold objects that have survived at least one young generation collection ◦ i.e. given additional chances to die before being considered “old enough” to be promoted to the old generation.
  24. 24.  Both young and old collections are done serially (using a single CPU), in a stop-the world fashion.  Application execution is halted while collection is taking place
  25. 25.  The collector then performs sliding compaction, sliding the live objects towards the beginning of the old generation space, leaving any free space in a single contiguous chunk at the opposite end.  (mark-sweep-compact collection algorithm)
  26. 26.  Non-compacting..
  27. 27. -Xms<min> //initial heap size -Xmx<max> //max heap size -XX:PermSize= //initial perm size -XX:MaxPermSize= //max perm size -XX:MinHeapFreeRatio=<minimum> -XX:MaxHeapFreeRatio=<maximum> -XX:SurvivorRatio=6 -XX:+UseSerialGC -XX:+UseParallelGC -XX:+UseConcMarkSweepGC -XX:ParallelGCThreads=<N> -XX:+HeapDumpOnOutOfMemoryError
  28. 28.  -verbose:gc  [GC 325816K->83372K(776768K), 0.2454258 secs] [Full GC 267628K->83769K(776768K), 1.8479984 secs]  [GC (1)->(2)(3), (4) secs]  (1->2) Combined size of live objects before and after garbage collection.  (3) Amount of space usable for java objects without requesting more memory from the operating system.  (4) time taken to perform GC.  -XX:+PrintGCDetails : print more details  -XX:+PrintGCTimeStamps : print timestamp
  29. 29.  Variant : ◦ Java heap space / Requested array size exceeds VM limit = heap size issue ◦ PermGen space = no memory for creating new class. ◦ unable to create new native thread / <reason> <stacktrace> (Native method) = no memory available for allocation of Thread (native stacktrace) ◦ request <size> bytes for <reason>. Out of swap space? = no memory left in OS.  Doesn’t mean no memory left : ◦ If >98% of the total time is spent in GC and only less than 2% of the heap is recovered. ◦ Adding element to Array require new Array creation, and no enough space in any generation.
  30. 30.  NetBeans Profiler  Eclipse : TPTP, MAT, Profiling, JVMMonitor, etc..  Java : Jconsole, jstat  JProfiler  AppDynamics  JBossProfiler  JProbe  JRAT, JMAP, etc…
  31. 31.  Location: Local or Remote.  GUI: Online or Offline.  Time: Attach or started for profiling.  CPU: Sampled or Instrumented  Classes: Filtered or not filtered.  Type : Web Server or Standalone.  etc..
  32. 32.  We will try 3 profilers: ◦ NetBeans Profiler ◦ JProfiler ◦ Eclipse TPTP
  33. 33.  Detecting hotspots
  34. 34.  Blocking Threads
  35. 35.  Heap is growing …
  36. 36.  Easy actually it is the Same way 
  37. 37.  Attach to the running server …
  38. 38.  Add triggers to define what to record and to save the snapshots..
  39. 39.  The session is added to configuration file with “id” example : ◦ <session id="119" ◦ …. ◦ </session>  Now in run command add the following:  - agentpath:D:PROGRA~1JPROFI~1binwind owsjprofilerti.dll=offline,id=119;
  40. 40.  Same everything 
  41. 41.  For More information refer to Java EE 7 performance tuning and optimization book.  The book is published by Packt Publishing. ◦ http://www.packtpub.com/java-ee-7- performance-tuning-and-optimization/book ◦ http://www.amazon.com/dp/178217642X/?tag=pa cktpubli-20 ◦ http://www.amazon.co.uk/dp/178217642X/?tag=p acktpubli-21
  42. 42.  http://www.oracle.com/technetwork/java/javase /memorymanagement-whitepaper-150215.pdf  http://docs.oracle.com/javase/specs/jvms/se7/h tml/jvms-2.html  http://www.oracle.com/technetwork/java/javase /gc-tuning-6-140523.html  http://docs.oracle.com/javase/tutorial/essential/ concurrency/procthread.html  http://java-source.net/open-source/profilers  www.ej-technologies.com/  http://profiler.netbeans.org/  http://www.eclipse.org/tptp/  http://www.petefreitag.com/articles/gctuning/
  43. 43.  Introduction  Basic Java Concepts ◦ Concurrency ◦ Memory Management  Java Profiler Tools ◦ NetBeans Profiler ◦ JProfiler ◦ Eclipse TPTP
  44. 44. http://osama-oransa.blogspot.com/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×