SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Downloaden Sie, um offline zu lesen
http://osama-oransa.blogspot.com/
 Introduction
 Basic Java Concepts
◦ Concurrency
◦ Memory Management
 Java Profiler Tools
◦ NetBeans Profiler
◦ JProfiler
◦ Eclipse TPTP
 Questions
 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.
 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.
 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.
 Hardware
◦ CPU
◦ Network
◦ Memory
◦ Storage
 Software
◦ Operating System
◦ Libraries, Drivers and Utilities.
◦ Application
 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.
 Good but sometimes you can consider:
◦ CPU :
 Use MT.
 Change workflow.
◦ Memory :
 Utilize more memory in caching.
 Change architecture.
 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.
 Vector, Stack, Hashtable are deprecated
 For single threaded use :
◦ ArrayList
◦ Deque
◦ HashMap
 For MT use : (a lot of other alternatives)
◦ CopyOnWriteArrayList
◦ ConcurrentLinkedDeque
◦ ConcurrentHashMap
 Concurrency
 Memory Management
 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.
 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
 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.
 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.
 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();
}
}
 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.
 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.
 Use Generational Collection
◦ Memory is divided into generations, that is,
separate pools holding objects of different ages.
 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.
 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.
 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.
 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.
 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
 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)
 Non-compacting..
-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
 -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
 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.
 NetBeans Profiler
 Eclipse : TPTP, MAT, Profiling, JVMMonitor,
etc..
 Java : Jconsole, jstat
 JProfiler
 AppDynamics
 JBossProfiler
 JProbe
 JRAT, JMAP, etc…
 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..
 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 command add the following:
 -
agentpath:D:PROGRA~1JPROFI~1binwind
owsjprofilerti.dll=offline,id=119;
 Same everything 
 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
 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/
 Introduction
 Basic Java Concepts
◦ Concurrency
◦ Memory Management
 Java Profiler Tools
◦ NetBeans Profiler
◦ JProfiler
◦ Eclipse TPTP
http://osama-oransa.blogspot.com/

Weitere ähnliche Inhalte

Was ist angesagt?

Java performance tuning
Java performance tuningJava performance tuning
Java performance tuningJerry Kurian
 
Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)aragozin
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkDror Bereznitsky
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?Roman Elizarov
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaIsuru Perera
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsCarol McDonald
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in androidRakesh Jha
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHoang Nguyen
 
Java concurrency in practice
Java concurrency in practiceJava concurrency in practice
Java concurrency in practiceMikalai Alimenkou
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Roman Elizarov
 
Java Threads: Lightweight Processes
Java Threads: Lightweight ProcessesJava Threads: Lightweight Processes
Java Threads: Lightweight ProcessesIsuru Perera
 
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGSylvain Wallez
 
Build, logging, and unit test tools
Build, logging, and unit test toolsBuild, logging, and unit test tools
Build, logging, and unit test toolsAllan Huang
 
DotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NETDotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NETMaarten Balliauw
 

Was ist angesagt? (20)

Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own Benchmark
 
Java in flames
Java in flamesJava in flames
Java in flames
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
JVM
JVMJVM
JVM
 
DIY Java Profiling
DIY Java ProfilingDIY Java Profiling
DIY Java Profiling
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
 
The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Java concurrency in practice
Java concurrency in practiceJava concurrency in practice
Java concurrency in practice
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
 
Java Threads: Lightweight Processes
Java Threads: Lightweight ProcessesJava Threads: Lightweight Processes
Java Threads: Lightweight Processes
 
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
 
Build, logging, and unit test tools
Build, logging, and unit test toolsBuild, logging, and unit test tools
Build, logging, and unit test tools
 
DotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NETDotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NET
 

Andere mochten auch

Hands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandHands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandC2B2 Consulting
 
Java profiling Do It Yourself
Java profiling Do It YourselfJava profiling Do It Yourself
Java profiling Do It Yourselfaragozin
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVMStaffan Larsen
 
JavaOne 2014: Java Debugging
JavaOne 2014: Java DebuggingJavaOne 2014: Java Debugging
JavaOne 2014: Java DebuggingChris Bailey
 
Debugging Your Production JVM
Debugging Your Production JVMDebugging Your Production JVM
Debugging Your Production JVMkensipe
 
Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages ToolchainTowards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages ToolchainAttila Szegedi
 
Hotspot Garbage Collection - The Useful Parts
Hotspot Garbage Collection - The Useful PartsHotspot Garbage Collection - The Useful Parts
Hotspot Garbage Collection - The Useful PartsjClarity
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applicationspkoza
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5osa_ora
 
Real Life Java EE Performance Tuning
Real Life Java EE Performance TuningReal Life Java EE Performance Tuning
Real Life Java EE Performance TuningC2B2 Consulting
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsosa_ora
 
Vortragsreihe Dortmund: Unified Development Environments
Vortragsreihe Dortmund: Unified Development EnvironmentsVortragsreihe Dortmund: Unified Development Environments
Vortragsreihe Dortmund: Unified Development EnvironmentsThorsten Kamann
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterAttila Szegedi
 

Andere mochten auch (13)

Hands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandHands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx Poland
 
Java profiling Do It Yourself
Java profiling Do It YourselfJava profiling Do It Yourself
Java profiling Do It Yourself
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVM
 
JavaOne 2014: Java Debugging
JavaOne 2014: Java DebuggingJavaOne 2014: Java Debugging
JavaOne 2014: Java Debugging
 
Debugging Your Production JVM
Debugging Your Production JVMDebugging Your Production JVM
Debugging Your Production JVM
 
Towards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages ToolchainTowards JVM Dynamic Languages Toolchain
Towards JVM Dynamic Languages Toolchain
 
Hotspot Garbage Collection - The Useful Parts
Hotspot Garbage Collection - The Useful PartsHotspot Garbage Collection - The Useful Parts
Hotspot Garbage Collection - The Useful Parts
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5
 
Real Life Java EE Performance Tuning
Real Life Java EE Performance TuningReal Life Java EE Performance Tuning
Real Life Java EE Performance Tuning
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tips
 
Vortragsreihe Dortmund: Unified Development Environments
Vortragsreihe Dortmund: Unified Development EnvironmentsVortragsreihe Dortmund: Unified Development Environments
Vortragsreihe Dortmund: Unified Development Environments
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @Twitter
 

Ähnlich wie Guide to Java Concurrency, Memory Management and Profiling Tools

Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
Intro To .Net Threads
Intro To .Net ThreadsIntro To .Net Threads
Intro To .Net Threadsrchakra
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performanceRoger Xia
 
CrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataRaphael do Vale
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsPhillip Koza
 
Exploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinarExploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinarMaarten Balliauw
 
Aleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_DevelopmentAleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_DevelopmentCiklum
 
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...Maarten Balliauw
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfjexp
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementEmery Berger
 
Java Multithreading
Java MultithreadingJava Multithreading
Java MultithreadingRajkattamuri
 
Java multithreading
Java multithreadingJava multithreading
Java multithreadingMohammed625
 
Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Nikolay Savvinov
 
Multithreading
MultithreadingMultithreading
MultithreadingF K
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1Viên Mai
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it worksMindfire Solutions
 

Ähnlich wie Guide to Java Concurrency, Memory Management and Profiling Tools (20)

Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Intro To .Net Threads
Intro To .Net ThreadsIntro To .Net Threads
Intro To .Net Threads
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performance
 
CrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked data
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
Exploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinarExploring .NET memory management - JetBrains webinar
Exploring .NET memory management - JetBrains webinar
 
Aleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_DevelopmentAleksandr_Butenko_Mobile_Development
Aleksandr_Butenko_Mobile_Development
 
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
multithreading
multithreadingmultithreading
multithreading
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
 
Java Multithreading
Java MultithreadingJava Multithreading
Java Multithreading
 
Java multithreading
Java multithreadingJava multithreading
Java multithreading
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 

Kürzlich hochgeladen

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Kürzlich hochgeladen (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Guide to Java Concurrency, Memory Management and Profiling Tools

  • 2.  Introduction  Basic Java Concepts ◦ Concurrency ◦ Memory Management  Java Profiler Tools ◦ NetBeans Profiler ◦ JProfiler ◦ Eclipse TPTP  Questions
  • 3.
  • 4.  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.
  • 5.  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.
  • 6.  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.
  • 7.  Hardware ◦ CPU ◦ Network ◦ Memory ◦ Storage  Software ◦ Operating System ◦ Libraries, Drivers and Utilities. ◦ Application
  • 8.  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.
  • 9.  Good but sometimes you can consider: ◦ CPU :  Use MT.  Change workflow. ◦ Memory :  Utilize more memory in caching.  Change architecture.
  • 10.  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.
  • 11.  Vector, Stack, Hashtable are deprecated  For single threaded use : ◦ ArrayList ◦ Deque ◦ HashMap  For MT use : (a lot of other alternatives) ◦ CopyOnWriteArrayList ◦ ConcurrentLinkedDeque ◦ ConcurrentHashMap
  • 12.
  • 14.  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.
  • 15.  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
  • 16.  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.
  • 17.  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.
  • 18.  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(); } }
  • 19.  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.
  • 20.  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.
  • 21.
  • 22.  Use Generational Collection ◦ Memory is divided into generations, that is, separate pools holding objects of different ages.
  • 23.  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.
  • 24.  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.
  • 25.  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.
  • 26.  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.
  • 27.  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
  • 28.
  • 29.
  • 30.  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)
  • 32.
  • 33.
  • 34. -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
  • 35.  -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
  • 36.  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.
  • 37.
  • 38.  NetBeans Profiler  Eclipse : TPTP, MAT, Profiling, JVMMonitor, etc..  Java : Jconsole, jstat  JProfiler  AppDynamics  JBossProfiler  JProbe  JRAT, JMAP, etc…
  • 39.  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..
  • 40.  We will try 3 profilers: ◦ NetBeans Profiler ◦ JProfiler ◦ Eclipse TPTP
  • 41.
  • 42.
  • 44.
  • 46.  Heap is growing …
  • 47.
  • 48.
  • 49.  Easy actually it is the Same way 
  • 50.
  • 51.
  • 52.  Attach to the running server …
  • 53.
  • 54.  Add triggers to define what to record and to save the snapshots..
  • 55.  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;
  • 56.
  • 57.
  • 59.
  • 60.  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
  • 61.  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/
  • 62.  Introduction  Basic Java Concepts ◦ Concurrency ◦ Memory Management  Java Profiler Tools ◦ NetBeans Profiler ◦ JProfiler ◦ Eclipse TPTP