SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
INSIDE THE JAVA VIRTUAL MACHINE

   Memory Management and Troubleshooting



                Filip Hanik
           Covalent Technologies
             August 29, 2007
                                           1
Who am I?
fhanik@apache.org
Tomcat Committer / ASF member
Co-designed the Comet implementation
Implemented NIO connector in 6
Responsible for session replication and
clustering
Been involved with ASF since 2001
Member, Covalent Technical Team
                                          2
What are we Talking About?



Internals of Java Memory
Spoken from a Java developer’s standpoint
For other Java developers and system
administrators




                                            3
Agenda


Understanding the Java Memory Layout
Out Of Memory Errors
  Causes
  Solution
Garbage Collection Basics
Java Tuning Options – Time Constraint
Questions and Answers
                                        4
Storing Data in Memory

Java runs as a single process
   Does not share memory with other processes
Each process allocates memory
   We call this process heap
Ways to allocate memory in a process
  C (malloc and free)
  C++ (new and delete)
  Java (new and dereference -> Garbage
  Collection)
                                                5
Storing Data in Memory

JVM manages the process heap
  In most cases
  JNI managed memory would be an exception,
  and there are others
No shared memory between processes
   At least not available through the Java API
JVM creates a Java Heap
  Part of the process heap
  Configured through –Xmx and –Xms settings
                                                 6
The JVM Process Heap

       OS Memory (RAM)


  Process Heap (java/java.exe)


Java Object Heap

              Everything else…
                                 7
JVM Process Heap


Maximum size is limited
  32 bit size, roughly 2GB
  64 bit, much much larger ☺
If 2GB is the max for the process
    -Xmx1800m –Xms1800m – not very
    good
    Leaves no room for anything else

                                       8
Java Object Heap

Also referred to as Java Heap
   Often confused with JVM process heap
Stores Java Objects
   instances of classes
   and the data the objects contain
      Primitives
      References


                                          9
Benefits of the Java Heap

Pre-allocate large blocks of memory
Allocation of small amounts of memory is very fast
No need to fish for a free memory segment in
RAM
No fragmentation
Continuous memory blocks can make a big
difference
NullPointerException vs. General Access Fault
    NPE runtime error
    GAF crash the process
                                                     10
Gotcha #1


-Xmx, -Xms and –Xmn
  Only controls the Java Object Heap
  Often misunderstood to control the
  process heap
Confusion leads to incorrect tuning
  And in some cases, the situation
  worsens


                                       11
Java Object Heap

So how is the Java Heap allocated?
-XX:MinHeapFreeRatio=
     Default is 40 (40%)
     When the JVM allocates memory, it allocates enough to
     get 40% free
     Huge chunks, very large default
     Not important when –Xms == -Xmx
-XX:MaxHeapFreeRatio=
     Default 70%
     To avoid over allocation
     To give back memory not used
As you can see, to provide performance and avoid
fragmentation, excessively large blocks are allocated each
time
                                                             12
Java Object Heap

Object allocation statistics
  80-98% of newly allocated are extremely
  short lived (few million instructions)
  80-98% die before another megabyte
  has been allocated
  Typical programs
Tomcat Core (no webapps)
  Lots of long lived objects
  Still a small memory footprint
                                            13
Java Object Heap

        Java Object Heap (-Xmx/-Xms)


    Young Generation

                         Old Generation

A good size for the YG is 33% of the total heap
                                                  14
Java Object Heap
Young Generation
  All new objects are created here
  Only moved to Old Gen if they survive
  one or more minor GC
  Sized Using
     -Xmn – not preferred (fixed value)
     -XX:NewRatio=<value> - preferred
     (dynamic)
Survivor Spaces
      2, used during the GC algorithm
      (minor collections)                 15
Young Generation
                    Young size(-XX:NewRatio )
                 Survivor Ratio(-XX:SurvivorRatio )


Eden Space                         Survivor Space



 New Objects
   2Mb default

                           To         From
                              64Kb default

                                                      16
Gotcha #2


Problem
   Multithreaded apps create new objects
   at the same time
   New objects are always created in the
   EDEN space
   During object creation, memory is locked
   On a multi CPU machine (threads run
   concurrently) there can be contention

                                              17
Gotcha #2
Solution
    Allow each thread to have a private piece of the EDEN
    space
Thread Local Allocation Buffer
    -XX:+UseTLAB
    -XX:TLABSize=<size in kb>
    -XX:+ResizeTLAB
    (On by default on multi CPU machines and newer JDK)
Analyse TLAB usage
    -XX:+PrintTLAB
JDK 1.5 and higher (GC ergonomics)
   Dynamic sizing algorithm, tuned to each thread

                                                            18
Old Generation



          Tenured Space
         5Mb min 44Mb max (default)


Garbage collection presentation will
explain in detail how these spaces
are used during the GC process.

                                       19
JVM Process Heap

Java Object Heap
   A handful, but a small part of the story
       OS Memory (RAM)

  Process Heap (java/java.exe)

Java Object Heap

               Everything else…
                                              20
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread Stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI Allocated Memory
                            21
Permanent Space
Permanent Generation
  Permanent Space (name for it)
  4Mb initial, 64Mb max
  Stores classes, methods and other meta
  data
  -XX:PermSize=<value> (initial)
  -XX:MaxPermSize=<value> (max)
Common OOM for webapp reloads
Separate space for pre-historic reasons
  Early days of Java, class GC was not
  common, reduces size of the Java Heap    22
Gotcha #3

Permanent Space Memory Errors
   Too many classes loaded
   Classes are not being GC:ed
   Unaffected by –Xmx flag
Identified by
   java.lang.OutOfMemoryError:
   PermGen space
Many situations, increasing max perm size will
help
   i.e., no leak, but just not enough memory
   Others will require to fix the leak
                                                 23
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread Stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI Allocated Memory
                            24
Code Generation


Converting byte code into native code
Very rare to cause memory problems
JVM will most likely crash if it doesn’t have
enough mem for this operation
  Never seen it though




                                                25
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread Stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI Allocated Memory
                            26
TCP connections

Each connection contains two buffers
   Receive buffer ~37k
   Send buffer ~25k
Configured in Java code
  So might not be exposed through applications
  configuration
Usually hit other limits than memory before an
error happen
    IOException: Too many open files (for
    example)
                                                 27
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread Stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI Allocated Memory
                            28
Thread Stacks


Each thread has a separate memory space
called “thread stack”
Configured by –Xss
Default value depends on OS/JVM
As number of threads increase, memory
usage increases


                                          29
Gotcha #4

java.lang.OutOfMemoryError:
unable to create new native thread
Solution
    Decrease –Xmx and/or
    Decrease –Xss
    Or, you have a thread leak, fix the program
Gotcha
    Increasing –Xmx (32bit systems) will leave less room for
    threads if it is being used, hence the opposite of the
    solution

    Too low –Xss value can cause
    java.lang.StackOverflowError
                                                               30
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI Allocated Memory
                            31
Direct Memory Space


Ability to let Java developers map memory
outside the Java Object Heap
java.nio.ByteBuffer.allocateDirect
java.lang.OutOfMemoryError:
Direct buffer memory
Adjusted by
   -XX:MaxDirectMemorySize=<value>

                                            32
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI Allocated Memory
                            33
JNI

Code needs memory
  Usually very little
JNI programs also allocate memory
  Error allocating
  memory.[NativeMemory.c] (my code)
  JVM goes berserk or crashes or if the
  JNI code can handle it gracefully, you’re
  lucky
Linux way of dealing with mem leak
   Kill the process!
                                              34
JVM Process Heap
Everything else…

     Permanent Space
     Code Generation
     Socket Buffers
     Thread stacks
     Direct Memory Space
     JNI Code
     Garbage Collection
     JNI allocated memory
                            35
Garbage Collection


Also uses memory
   Threads
   Memory to store GC info
If there isn’t enough memory for GC, then
the system will not be functioning at all



                                            36
GC History

First time around 1959 – LISP language
The idea
  automatic memory cleanup
  Easier to write code
  Easier to debug
What it does
  Maps memory in memory
  The Java Object Heap is such a map

                                         37
Phases of GC
Lock it down
  All objects that are to take part in the GC
  must be locked, so that they don’t
  mutate
Mark
  Iterate through all objects
  Mark the “unreachable” as garbage
Sweep
  Remove all previously marked objects
  Reclaim memory                                38
Early Version of Java
Garbage Collector wasn’t very well tuned
Only one algorithm was available
Mark and Sweep entire heap
  Takes a very long time
  Time spent is dependent on the size of the
  heap
  That is why the “Permanent Space” was
  invented
      And cause un/reloading of classes wasn’t
      very common either
Also known as “stop-the-world” gc
   The entire JVM is locked down                 39
Strategies
Stop The World
Incremental
    Time GC with new object creation
    If GC runs, suspend new allocation
Concurrent/Parallel
    Allocation happens at the same time as GC
    Very complex locking regimes
    Generations/Spaces make it easier
CMS stands for
    Concurrent
    Mark
    Sweep
                                                40
How It Works

       Eden Space                Survivor Space



                               From       To


              Tenured Space
4. Next time Eden is –
1. New object isis fullfullminor 1st
3. Copy EDEN created
2. When surviving objects into collection
Copy from and to 2nd
5. If 2nd fillsEdenobjects remain in Eden or 1st
survivor space
Copy from copied nd the tenured
               1st to 2to
These get                                        41
How it Works

One survivor space is always empty
  Serves as destination for minor
  collections
Objects get copied to the tenured space
when the 2nd survivor space fills up
Major collections occur when the tenured
space fills up
   Major collections free up Eden and both
   survivor spaces
                                             42
New and Fancy

Concurrent/Parallel Garbage Collection
-XX:+UseParNewGC
   Parallel GC in the New(Young)
   Generation
-XX:+UseConcMarkSweepGC
   Concurrent in the Old generation
Use these two combined
  Multi CPU box can take advantage of
  this
                                         43
Sun Recommended
GC Settings
   -XX:+UseConcMarkSweepGC
   -XX:+CMSIncrementalMode
   -XX:+CMSIncrementalPacing
   -XX:CMSIncrementalDutyCycleMin=0
   -XX:+CMSIncrementalDutyCycle=10
   -XX:+UseParNewGC
   -XX:+CMSPermGenSweepingEnabled
To analyze what is going on
   -XX:+PrintGCDetails
   -XX:+PrintGCTimeStamps
   -XX:-TraceClassUnloading
                                      44
Minor Notes

-XX:+UseParallelGC <> -XX:+UseParNewGC
-XX:ParallelGCThreads=<nr of cpu>
   Use with ParallelGC setting
If you have 4 cpus and 1 JVM
   Set value to 4
If you have 4 cpus and 2 JVM
   Set value to 2
If you have 4 cpus and 6 JVM
   Set value to 2
                                         45
GC Ergonomics

Started with JDK 1.5
JVM is self trained and GC strategy adapts
Rules/Guidelines can be set using command line
options
    Max pause time goal
       The longest pause time to suspend
       application
    Throughput goal
       Time spent GC vs. time spent outside GC
Not guaranteed
                                                 46
Out Of Memory Errors

There is a seamless way to get info
  -XX:+HeapDumpOnOutOfMemoryError
No performance impact during runtime
Dumping a –Xmx512m heap
  Create a 512MB .hprof file
  JVM is “dead” during dumping
  Restarting JVM during this dump will
  cause unusable .hprof file
                                         47
Gotcha’s

Major collections don’t run until tenured is
full
What does that mean?
  -Xmx1024m
  Current heap could be 750MB
  500MB of “dead” objects
  If VM is idle, could stay like that for a
  very long time
  Wasting 500MB of RAM for an idle JVM
                                               48
Monitoring Agents

Monitor memory usage
If system is idle, force a GC
Can be done automatically and with remote
agents
Example would be:
www.yourkit.com
And script the client to take telemetry
readings from an embedded agent
                                            49
Thank You


fhanik@covalent.net
For support information contact Covalent
   support@covalent.com,
   sales@covalent.com
   www.covalent.com
   800/444-1935 or 925/974-8800
Question and Answer time!!

                                           50
The Enterprise Open Source Support Company




                                             51

Weitere ähnliche Inhalte

Was ist angesagt?

JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir Ivanov
ZeroTurnaround
 
Dissecting the Hotspot JVM
Dissecting the Hotspot JVMDissecting the Hotspot JVM
Dissecting the Hotspot JVM
Ivan Ivanov
 
JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languages
Edgar Espina
 
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
Vladimir Ivanov
 

Was ist angesagt? (20)

Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
 
Java introduction with JVM architecture
Java introduction with JVM architectureJava introduction with JVM architecture
Java introduction with JVM architecture
 
Java Virtual Machine
Java Virtual MachineJava Virtual Machine
Java Virtual Machine
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir Ivanov
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 
JVM Internals (2015)
JVM Internals (2015)JVM Internals (2015)
JVM Internals (2015)
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVM
 
Architecture diagram of jvm
Architecture diagram of jvmArchitecture diagram of jvm
Architecture diagram of jvm
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compiler
 
Dissecting the Hotspot JVM
Dissecting the Hotspot JVMDissecting the Hotspot JVM
Dissecting the Hotspot JVM
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
QSpiders - Memory (JVM architecture)
QSpiders - Memory (JVM architecture)QSpiders - Memory (JVM architecture)
QSpiders - Memory (JVM architecture)
 
JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languages
 
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
JVM
JVMJVM
JVM
 
Java 2
Java 2Java 2
Java 2
 
3. jvm
3. jvm3. jvm
3. jvm
 

Andere mochten auch

Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
Yoav Avrahami
 

Andere mochten auch (20)

Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
 
The Java Carputer
The Java CarputerThe Java Carputer
The Java Carputer
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 
Carbon and OSGi Deep Dive
Carbon and OSGi Deep DiveCarbon and OSGi Deep Dive
Carbon and OSGi Deep Dive
 
Project Jigsaw in JDK9
Project Jigsaw in JDK9Project Jigsaw in JDK9
Project Jigsaw in JDK9
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
Lessons Learnt With Lambdas and Streams in JDK 8
Lessons Learnt With Lambdas and Streams in JDK 8Lessons Learnt With Lambdas and Streams in JDK 8
Lessons Learnt With Lambdas and Streams in JDK 8
 
Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGi
 
Java Classloaders
Java ClassloadersJava Classloaders
Java Classloaders
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
The Full Stack Java Developer - Josh Long
The Full Stack Java Developer - Josh LongThe Full Stack Java Developer - Josh Long
The Full Stack Java Developer - Josh Long
 
JDK 9: Big Changes To Make Java Smaller
JDK 9: Big Changes To Make Java SmallerJDK 9: Big Changes To Make Java Smaller
JDK 9: Big Changes To Make Java Smaller
 
Introduction to-osgi
Introduction to-osgiIntroduction to-osgi
Introduction to-osgi
 
Pitfalls of migrating projects to JDK 9
Pitfalls of migrating projects to JDK 9Pitfalls of migrating projects to JDK 9
Pitfalls of migrating projects to JDK 9
 
OSGi Blueprint Services
OSGi Blueprint ServicesOSGi Blueprint Services
OSGi Blueprint Services
 
Modularization With Project Jigsaw in JDK 9
Modularization With Project Jigsaw in JDK 9Modularization With Project Jigsaw in JDK 9
Modularization With Project Jigsaw in JDK 9
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
 

Ähnlich wie Inside The Java Virtual Machine

Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
Vladimir Khokhryakov
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limits
Davide Carnevali
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)
Marcos García
 

Ähnlich wie Inside The Java Virtual Machine (20)

Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
 
Troubleshooting XLConnect - OutofMemoryError(java) GC overhead limit exceeded
Troubleshooting XLConnect - OutofMemoryError(java) GC overhead limit exceededTroubleshooting XLConnect - OutofMemoryError(java) GC overhead limit exceeded
Troubleshooting XLConnect - OutofMemoryError(java) GC overhead limit exceeded
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-Confoo
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limits
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Javasession10
Javasession10Javasession10
Javasession10
 
OOPs, OOMs, oh my! Containerizing JVM apps
OOPs, OOMs, oh my! Containerizing JVM appsOOPs, OOMs, oh my! Containerizing JVM apps
OOPs, OOMs, oh my! Containerizing JVM apps
 
Java and cgroups eng
Java and cgroups engJava and cgroups eng
Java and cgroups eng
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
 
Heapoff memory wtf
Heapoff memory wtfHeapoff memory wtf
Heapoff memory wtf
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)
 
It's always sunny with OpenJ9
It's always sunny with OpenJ9It's always sunny with OpenJ9
It's always sunny with OpenJ9
 
7 jvm-arguments-v1
7 jvm-arguments-v17 jvm-arguments-v1
7 jvm-arguments-v1
 
QCon 2017 - Java/JVM com Docker em produção: lições das trincheiras
QCon 2017 - Java/JVM com Docker em produção: lições das trincheirasQCon 2017 - Java/JVM com Docker em produção: lições das trincheiras
QCon 2017 - Java/JVM com Docker em produção: lições das trincheiras
 
A quick view about Java Virtual Machine
A quick view about Java Virtual MachineA quick view about Java Virtual Machine
A quick view about Java Virtual Machine
 
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
 
ContainerWorkloadwithSemeru.pdf
ContainerWorkloadwithSemeru.pdfContainerWorkloadwithSemeru.pdf
ContainerWorkloadwithSemeru.pdf
 
Devoxx Fr 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneu...
Devoxx Fr 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneu...Devoxx Fr 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneu...
Devoxx Fr 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneu...
 
Mastering java in containers - MadridJUG
Mastering java in containers - MadridJUGMastering java in containers - MadridJUG
Mastering java in containers - MadridJUG
 

Mehr von elliando dias

Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 

Mehr von elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Kürzlich hochgeladen

Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
Matteo Carbone
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
lizamodels9
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Sheetaleventcompany
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 

Kürzlich hochgeladen (20)

(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 

Inside The Java Virtual Machine

  • 1. INSIDE THE JAVA VIRTUAL MACHINE Memory Management and Troubleshooting Filip Hanik Covalent Technologies August 29, 2007 1
  • 2. Who am I? fhanik@apache.org Tomcat Committer / ASF member Co-designed the Comet implementation Implemented NIO connector in 6 Responsible for session replication and clustering Been involved with ASF since 2001 Member, Covalent Technical Team 2
  • 3. What are we Talking About? Internals of Java Memory Spoken from a Java developer’s standpoint For other Java developers and system administrators 3
  • 4. Agenda Understanding the Java Memory Layout Out Of Memory Errors Causes Solution Garbage Collection Basics Java Tuning Options – Time Constraint Questions and Answers 4
  • 5. Storing Data in Memory Java runs as a single process Does not share memory with other processes Each process allocates memory We call this process heap Ways to allocate memory in a process C (malloc and free) C++ (new and delete) Java (new and dereference -> Garbage Collection) 5
  • 6. Storing Data in Memory JVM manages the process heap In most cases JNI managed memory would be an exception, and there are others No shared memory between processes At least not available through the Java API JVM creates a Java Heap Part of the process heap Configured through –Xmx and –Xms settings 6
  • 7. The JVM Process Heap OS Memory (RAM) Process Heap (java/java.exe) Java Object Heap Everything else… 7
  • 8. JVM Process Heap Maximum size is limited 32 bit size, roughly 2GB 64 bit, much much larger ☺ If 2GB is the max for the process -Xmx1800m –Xms1800m – not very good Leaves no room for anything else 8
  • 9. Java Object Heap Also referred to as Java Heap Often confused with JVM process heap Stores Java Objects instances of classes and the data the objects contain Primitives References 9
  • 10. Benefits of the Java Heap Pre-allocate large blocks of memory Allocation of small amounts of memory is very fast No need to fish for a free memory segment in RAM No fragmentation Continuous memory blocks can make a big difference NullPointerException vs. General Access Fault NPE runtime error GAF crash the process 10
  • 11. Gotcha #1 -Xmx, -Xms and –Xmn Only controls the Java Object Heap Often misunderstood to control the process heap Confusion leads to incorrect tuning And in some cases, the situation worsens 11
  • 12. Java Object Heap So how is the Java Heap allocated? -XX:MinHeapFreeRatio= Default is 40 (40%) When the JVM allocates memory, it allocates enough to get 40% free Huge chunks, very large default Not important when –Xms == -Xmx -XX:MaxHeapFreeRatio= Default 70% To avoid over allocation To give back memory not used As you can see, to provide performance and avoid fragmentation, excessively large blocks are allocated each time 12
  • 13. Java Object Heap Object allocation statistics 80-98% of newly allocated are extremely short lived (few million instructions) 80-98% die before another megabyte has been allocated Typical programs Tomcat Core (no webapps) Lots of long lived objects Still a small memory footprint 13
  • 14. Java Object Heap Java Object Heap (-Xmx/-Xms) Young Generation Old Generation A good size for the YG is 33% of the total heap 14
  • 15. Java Object Heap Young Generation All new objects are created here Only moved to Old Gen if they survive one or more minor GC Sized Using -Xmn – not preferred (fixed value) -XX:NewRatio=<value> - preferred (dynamic) Survivor Spaces 2, used during the GC algorithm (minor collections) 15
  • 16. Young Generation Young size(-XX:NewRatio ) Survivor Ratio(-XX:SurvivorRatio ) Eden Space Survivor Space New Objects 2Mb default To From 64Kb default 16
  • 17. Gotcha #2 Problem Multithreaded apps create new objects at the same time New objects are always created in the EDEN space During object creation, memory is locked On a multi CPU machine (threads run concurrently) there can be contention 17
  • 18. Gotcha #2 Solution Allow each thread to have a private piece of the EDEN space Thread Local Allocation Buffer -XX:+UseTLAB -XX:TLABSize=<size in kb> -XX:+ResizeTLAB (On by default on multi CPU machines and newer JDK) Analyse TLAB usage -XX:+PrintTLAB JDK 1.5 and higher (GC ergonomics) Dynamic sizing algorithm, tuned to each thread 18
  • 19. Old Generation Tenured Space 5Mb min 44Mb max (default) Garbage collection presentation will explain in detail how these spaces are used during the GC process. 19
  • 20. JVM Process Heap Java Object Heap A handful, but a small part of the story OS Memory (RAM) Process Heap (java/java.exe) Java Object Heap Everything else… 20
  • 21. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread Stacks Direct Memory Space JNI Code Garbage Collection JNI Allocated Memory 21
  • 22. Permanent Space Permanent Generation Permanent Space (name for it) 4Mb initial, 64Mb max Stores classes, methods and other meta data -XX:PermSize=<value> (initial) -XX:MaxPermSize=<value> (max) Common OOM for webapp reloads Separate space for pre-historic reasons Early days of Java, class GC was not common, reduces size of the Java Heap 22
  • 23. Gotcha #3 Permanent Space Memory Errors Too many classes loaded Classes are not being GC:ed Unaffected by –Xmx flag Identified by java.lang.OutOfMemoryError: PermGen space Many situations, increasing max perm size will help i.e., no leak, but just not enough memory Others will require to fix the leak 23
  • 24. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread Stacks Direct Memory Space JNI Code Garbage Collection JNI Allocated Memory 24
  • 25. Code Generation Converting byte code into native code Very rare to cause memory problems JVM will most likely crash if it doesn’t have enough mem for this operation Never seen it though 25
  • 26. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread Stacks Direct Memory Space JNI Code Garbage Collection JNI Allocated Memory 26
  • 27. TCP connections Each connection contains two buffers Receive buffer ~37k Send buffer ~25k Configured in Java code So might not be exposed through applications configuration Usually hit other limits than memory before an error happen IOException: Too many open files (for example) 27
  • 28. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread Stacks Direct Memory Space JNI Code Garbage Collection JNI Allocated Memory 28
  • 29. Thread Stacks Each thread has a separate memory space called “thread stack” Configured by –Xss Default value depends on OS/JVM As number of threads increase, memory usage increases 29
  • 30. Gotcha #4 java.lang.OutOfMemoryError: unable to create new native thread Solution Decrease –Xmx and/or Decrease –Xss Or, you have a thread leak, fix the program Gotcha Increasing –Xmx (32bit systems) will leave less room for threads if it is being used, hence the opposite of the solution Too low –Xss value can cause java.lang.StackOverflowError 30
  • 31. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread stacks Direct Memory Space JNI Code Garbage Collection JNI Allocated Memory 31
  • 32. Direct Memory Space Ability to let Java developers map memory outside the Java Object Heap java.nio.ByteBuffer.allocateDirect java.lang.OutOfMemoryError: Direct buffer memory Adjusted by -XX:MaxDirectMemorySize=<value> 32
  • 33. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread stacks Direct Memory Space JNI Code Garbage Collection JNI Allocated Memory 33
  • 34. JNI Code needs memory Usually very little JNI programs also allocate memory Error allocating memory.[NativeMemory.c] (my code) JVM goes berserk or crashes or if the JNI code can handle it gracefully, you’re lucky Linux way of dealing with mem leak Kill the process! 34
  • 35. JVM Process Heap Everything else… Permanent Space Code Generation Socket Buffers Thread stacks Direct Memory Space JNI Code Garbage Collection JNI allocated memory 35
  • 36. Garbage Collection Also uses memory Threads Memory to store GC info If there isn’t enough memory for GC, then the system will not be functioning at all 36
  • 37. GC History First time around 1959 – LISP language The idea automatic memory cleanup Easier to write code Easier to debug What it does Maps memory in memory The Java Object Heap is such a map 37
  • 38. Phases of GC Lock it down All objects that are to take part in the GC must be locked, so that they don’t mutate Mark Iterate through all objects Mark the “unreachable” as garbage Sweep Remove all previously marked objects Reclaim memory 38
  • 39. Early Version of Java Garbage Collector wasn’t very well tuned Only one algorithm was available Mark and Sweep entire heap Takes a very long time Time spent is dependent on the size of the heap That is why the “Permanent Space” was invented And cause un/reloading of classes wasn’t very common either Also known as “stop-the-world” gc The entire JVM is locked down 39
  • 40. Strategies Stop The World Incremental Time GC with new object creation If GC runs, suspend new allocation Concurrent/Parallel Allocation happens at the same time as GC Very complex locking regimes Generations/Spaces make it easier CMS stands for Concurrent Mark Sweep 40
  • 41. How It Works Eden Space Survivor Space From To Tenured Space 4. Next time Eden is – 1. New object isis fullfullminor 1st 3. Copy EDEN created 2. When surviving objects into collection Copy from and to 2nd 5. If 2nd fillsEdenobjects remain in Eden or 1st survivor space Copy from copied nd the tenured 1st to 2to These get 41
  • 42. How it Works One survivor space is always empty Serves as destination for minor collections Objects get copied to the tenured space when the 2nd survivor space fills up Major collections occur when the tenured space fills up Major collections free up Eden and both survivor spaces 42
  • 43. New and Fancy Concurrent/Parallel Garbage Collection -XX:+UseParNewGC Parallel GC in the New(Young) Generation -XX:+UseConcMarkSweepGC Concurrent in the Old generation Use these two combined Multi CPU box can take advantage of this 43
  • 44. Sun Recommended GC Settings -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:+CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+CMSPermGenSweepingEnabled To analyze what is going on -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-TraceClassUnloading 44
  • 45. Minor Notes -XX:+UseParallelGC <> -XX:+UseParNewGC -XX:ParallelGCThreads=<nr of cpu> Use with ParallelGC setting If you have 4 cpus and 1 JVM Set value to 4 If you have 4 cpus and 2 JVM Set value to 2 If you have 4 cpus and 6 JVM Set value to 2 45
  • 46. GC Ergonomics Started with JDK 1.5 JVM is self trained and GC strategy adapts Rules/Guidelines can be set using command line options Max pause time goal The longest pause time to suspend application Throughput goal Time spent GC vs. time spent outside GC Not guaranteed 46
  • 47. Out Of Memory Errors There is a seamless way to get info -XX:+HeapDumpOnOutOfMemoryError No performance impact during runtime Dumping a –Xmx512m heap Create a 512MB .hprof file JVM is “dead” during dumping Restarting JVM during this dump will cause unusable .hprof file 47
  • 48. Gotcha’s Major collections don’t run until tenured is full What does that mean? -Xmx1024m Current heap could be 750MB 500MB of “dead” objects If VM is idle, could stay like that for a very long time Wasting 500MB of RAM for an idle JVM 48
  • 49. Monitoring Agents Monitor memory usage If system is idle, force a GC Can be done automatically and with remote agents Example would be: www.yourkit.com And script the client to take telemetry readings from an embedded agent 49
  • 50. Thank You fhanik@covalent.net For support information contact Covalent support@covalent.com, sales@covalent.com www.covalent.com 800/444-1935 or 925/974-8800 Question and Answer time!! 50
  • 51. The Enterprise Open Source Support Company 51