SlideShare a Scribd company logo
Java™ Garbage Collection
Statistical Analysis 101.
Juarez Junior
System Architect – Unisys Global Outsourcing
Agenda.
  Java Heap Management
  Simple Garbage Collection Statistics
   • Generating the Data
   • Isolating the Data
   • Graphing the Data
   • Interpreting the Data
   • Improving Performance
  Advanced Garbage Collection Statistics
   • Generate, Isolate, Graph, Interpret, Improve
  Java Command Line Arguments Recap
Java Heap.
  Young Generation
   • Eden
       - Where new objects are created
   • Survivor spaces
       - Where garbage collector places objects that are still in use

  Old Generation
   • Where tenured objects are placed
  References
   • http://java.sun.com/docs/hotspot/gc/ (1.3.1)
   • http://java.sun.com/docs/hotspot/gc1.4.2/
Minor Garbage Collection.
  Occurs when no room in eden for new object
  Marks all reachable objects in eden and “from” survivor space
  Copies those objects to “to” survivor space
      • Updates references accordingly
      • If “to” survivor space fills, overflows to old generation
  Resets allocation pointer to start of eden


  H                                                A    B     C     D     E
  I                                                E    F     G H         G   I

            Old Generation                                Eden          From From
                                                                          To To
                                                                          Spaces
Major Garbage Collection.
  Occurs when insufficient room in old generation to hold to-be-
  tenured objects during a minor collection
    • Pessimistic – need sufficient space to hold all object in young generation
    • Pre-calculated – Minor collection reachable object algorithm run to
      determine exactly now many objects will be tenured
  Mark and Compact
   • Reachable objects are marked
   • Marked objects are moved to one end of the old generation

  J    K M M N O
         L O                      V W          A    B     C    D
  P    Q    R
            X     S    T    U     X            E    F     G    H              I
           Old Generation                            Eden           To From
                                                                    Spaces
Agenda.
  Java Heap Management
  Simple Garbage Collection Statistics
   • Generating the Data
   • Isolating the Data
   • Graphing the Data
   • Interpreting the Data
   • Improving Performance
  Advanced Garbage Collection Statistics
   • Generate, Isolate, Graph, Interpret, Improve
  Java Command Line Arguments Recap
Generating Simple GC Data.
      -verbose:gc command line option
        java ... –verbose:gc ... my.java.app ...
      Results:
              ...
              [GC        1860K->1388K(1984K),   0.0005059     secs]
  Minor
              [GC        1900K->1446K(1984K),   0.0006679     secs]
collections   [GC        1958K->1468K(2112K),   0.0006251     secs]
              [Full GC   1468K-> 195K(2112K),   0.0131045     secs]
 Major and    ...
                                                        Time it took
   minor
 collection                                 Total heap size
                                     Heap in use after collection
                             Heap in use before collection
Isolating the Simple GC Data.
...                                                              ...
[GC        1860K->1388K(1984K),   0.0005059   secs]
[GC        1900K->1446K(1984K),   0.0006679   secs]              1860,1388,0.0005059
[GC
[Full GC
           1958K->1468K(2112K),
           1468K-> 195K(2112K),
                                  0.0006251
                                  0.0131045
                                              secs]
                                              secs]   Analyzer   1900,1446,0.0006679
...
                                                                 1958,1468,0.0006251
                                                                 1468,195,0.0131045
                                                                 ...




 import java.util.regex.Matcher;                       Comma-separated
 import java.util.regex.Pattern;                        value (CSV) file
 ...
 Pattern p = Pattern.compile
     ("[(?:Full |)GC (d*)K->(d*)K(d*K), ([d.]*) secs]");
 Matcher m = p.matcher(simple_gc_data_output);
 while (m.find())
     fout.println(m.group(1) + "," + m.group(2) + "," + m.group(3));
Interpreting the Regular Expression.
  The ’’ char is an escape character, both in Java and in
  regular expressions.
  [(?:Full |)GC (d*)K->(d*)K(d*K), ([d.]*) secs]
   [(?:Full |)GC     - match literal ‘[Full GC ’ or ‘[GC ’
   (d*)K->   - capture all digits before the literal text ‘K->’
   (d*)K   - capture all digits before the literal text ‘K’
   (d*K)   - discard the digits and literal text ‘K’ within parenthesis
                  - capture all digits and decimal point after the
   , ([d.]*) secs]
    comma and space, and before the literal text ‘secs]’



[Full GC 1468K-> 195K(2112K), 0.0131045 secs]
Graphing the Simple GC Data.
  Load the CSV file into a spreadsheet
  Sum the third column - total time spent
  on GC
  Create fourth column
   • Third column * 10000 (or 100000)
   • Gets times within range of columns 1 and 2
  Create a graph containing columns
  1, 2 and 4.
Graphing in Excel.
 Select first column only
 Create an “XY (Scatter)” graph
 Wizard step 2, click Series tab
 and add columns 2 and 4 to
 the series.
  • Click Add
  • Name: Type or select row 1 cell
  • X Values: leave empty
  • Y Values: Select cells in column
 Suggest creating new sheet
 for the chart
Graphing in StarOffice.
 Swap the 3rd and 4th columns (seconds*10000 is now the
 3rd column)
 Select the first 3 columns
 and create chart
  • Put chart in new sheet
  • Select ‘lines’ chart type
  • Select ‘normal’ variant
 After chart is created
  • Turn off labels on the X axis
  • Change width of data series
    lines to 0.02” or higher.
Interpreting Graphed GC Data.
  Typical GC data graph
  For many GCs, the heap slowly
  fills as objects get moved to the
  old generation
   • Blue (or magenta) lines with
     positive slope

  Then a full GC happens
   • Drop in blue (or magenta) lines
   • Yellow dot in higher position
Interpreting Graphed GC Data.
Three Phases                       Phase 1   Phase 2   Phase 3

Phase 1
 • Working set equilibrium
 • Ideal graph
 • No full GC
Phase 2
 • Full GC with heap not full
      - High GC times (yellow
        dots above blue zig-zag)
 • App called System.GC()
Phase 3
 • Incremental working set
   equilibrium
 • Implies various sub-phases
   each of which adds to
   working set
Improving Performance, Before.
  Goal: 1000 business transactions in 12 minutes
  Heap set to: -Xms1024m –Xmx1024m
  18 minute run, 472 seconds (7.8 minutes) in garbage collection

                                                     Each GC is
                                                    freeing very
                                                   little memory
Improving Performance, After.
-Xms1024m –Xmx1024m -XX:NewSize=300m –XX:MaxNewSize=300m
12 minute run, 25 seconds in garbage collection
 • 70 collections instead of 8000 (no major/full collections)
 • Average collection freed 240MB instead of just 1MB
Agenda.
  Java Heap Management
  Simple Garbage Collection Statistics
   • Generating the Data
   • Isolating the Data
   • Graphing the Data
   • Interpreting the Data
   • Improving Performance
  Advanced Garbage Collection Statistics
   • Generate, Isolate, Graph, Interpret, Improve
  Java Command Line Arguments Recap
More GC Data.
    PrintGCDetails command line option
      java ... –XX:+PrintGCDetails ... my.java.app ...
    Results:
  Minor        [GC [DefNew: 17131K->1606K(18432K), 0.0082055 secs]
collection                 44904K->29379K(63488K), 0.0083625 secs]

               [GC [DefNew: 17990K->17990K(18432K), 0.0000839 secs]
                   [Tenured: 27772K->3759K(45056K), 0.0454394 secs]
Major and                    45763K->3759K(63488K), 0.0459597 secs]
  minor
collection                                              Time it took
                                                      Heap size
     Sizes are for young                      Heap in use after collection
       generation, old
  generation, and total heap            Heap in use before collection
And Even More GC Data.
   PrintHeapAtGC command line option
    • java ... –XX:+PrintHeapAtGC ... my.java.app ...
   Results:
 {Heap before GC invocations=422:
 Heap
   def new generation   total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
    eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
    from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
    to   space 2048K,   0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
   tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
     the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
   compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
     the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
   Heap after GC invocations=423:
 Heap
   def new generation   total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
    eden space 16384K,   0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
    from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
    to   space 2048K,   0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
   tenured generation   total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
     the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
   compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
     the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
 }
PrintHeapAtGC Data.
{Heap before GC invocations=422:
Heap
  def new generation   total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
   from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
   to   space 2048K,   0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
  tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  Heap after GC invocations=423:
Heap
  def new generation   total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K,   0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
   from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
   to   space 2048K,           Data from before GC
                       0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
  tenured generation   total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
}
PrintHeapAtGC Data.
{Heap before GC invocations=422:
Heap
  def new generation   total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
   from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
   to   space 2048K,          Data from after GC
                       0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
  tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  Heap after GC invocations=423:
Heap
  def new generation   total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K,   0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
   from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
   to   space 2048K,   0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
  tenured generation   total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
}
PrintHeapAtGC Data.
{Heap before GC invocations=422:
Heap
  def new generation   total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
   from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
   to   space 2048K,   0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
  Memory
  tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
  addresses:
    the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
     Memory
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
   -addresses
     start
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  Heap after GC invocations=423:
   - next
Heap
   - end
  def new generation
   eden space 16384K,
                       total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
                        0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
   from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
   to   space 2048K,   0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
  tenured generation   total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
}
PrintHeapAtGC Data.
{Heap before GC invocations=422:
Heap
  def new generation   total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
   from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
   to   space 2048K,   0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
       Before GC, eden ‘next’
  tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
          pointer is at end
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  Heap after GC invocations=423:
Heap
  def new generation   total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K,   0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
   from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
   to   space 2048K,   0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
  tenured generation   total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
                                                 After GC, eden ‘next’
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)

}
                                                  pointer is at start
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
PrintHeapAtGC Data.
{Heap before GC invocations=422:
Heap
  def new generation                                 For each generation
                       total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
   from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
   to   space 2048K,   0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
  tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  Heap after GC invocations=423:                     Memory in use
Heap
  def new generation   total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K,   0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
   from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
   to   space 2048K,   0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
  tenured generation   total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
                                                     Memory allocated
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
}
PrintHeapAtGC Data.
{Heap before GC invocations=422:
Heap                                    For each generational sub-space
  def new generation   total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000)
   from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000)
   to   space 2048K,   0% used [0x6fb40000, 0x6fb40000, 0x6fd40000)
  tenured generation   total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000)
                                                Percentage of that
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  Heap after GC invocations=423:              memory that is in use
Heap
  def new generation   total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000)
   eden space 16384K,   0% used [0x6eb40000, 0x6eb40000, 0x6fb40000)
   from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000)
   to   space 2048K,   0% used [0x6fd40000, 0x6fd40000, 0x6ff40000)
  tenured generation                       Amount of memory allocated
                       total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000)
    the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000)
  compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000)
    the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
}
Isolating the Data.
   Extract data
    • Need a very complex regular expression
    • CSV file, spreadsheet, with many columns
   Interesting data
    • Memory in use by each generation
        - Before and after each collection
    • Percent in use of “from space”                      New data
        - NOTE: “After” data same as next “Before” data    worth
                                                          graphing
Graphing and Analyzing the Data.
 “From Space” usage is between 10%
 and 60%
 Adjust from space size using
 SurvivorRatio option
  • -XX:SurvivorRatio=ratio
  • Eden-size = survivor-size * ratio
  • Eden-size + 2 * survivor-ratio = young-gen-
    size
 Example:
  • -XX:NewSize=200M –XX:SurvivorRatio=8
  • Eden: 160MB, each Survivor Space: 20MB
 Aim for 90-95% usage after collection
  • Typically, with large young generations, use
    larger ratio (e.g. 32)
Agenda.
  Java Heap Management
  Simple Garbage Collection Statistics
   • Generating the Data
   • Isolating the Data
   • Graphing the Data
   • Interpreting the Data
   • Improving Performance
  Advanced Garbage Collection Statistics
   • Generate, Isolate, Graph, Interpret, Improve
  Java Command Line Arguments Recap
Garbage Collection Info Options.
  -verbose:gc
   • Heap usage before and after GC
   • Time spent during GC
  -XX:+ PrintGCDetails
   • Generation and heap size before and after GC
   • Time spent during GC
  -XX:+ PrintHeapAtGC
   • Generation sizes before and after GC
   • Space sizes and percent in use before and after GC
   • Memory locations of the heap, its generations, and their spaces
Java Tuning Options.
  -Xmssizem, -Xmxsizem
   • Minimum and maximum heap size
   • Set both sizes to the same value
  -XX:NewSize=sizem, -XX:MaxNewSize=sizem
   • Minimum and maximum young generation size
   • Set both sizes to the same value
   • Set to about 1/3 or 1/4 the size of the heap.
  -XX:SurvivorRatio=ratio
   • Number of times the eden space is larger than the “from” space
   • Try for maximum of 90-95% usage
Conclusions.
  The HotSpot™ JVM provides a variety of options
  for gathering garbage collection statistics.
  Those statistics are easily extracted using
   • A simple Java application using
   • A regular expression
  The extracted data is easily graphed using a
  spreadsheet application.
  Examining the resulting graph
   • Tells a lot about what the application is doing
   • Enables selection of proper heap sizing to improve
     performance of the application.
Questions?

More Related Content

KEY
Reducing the time of heuristic algorithms for the Symmetric TSP
PDF
Large scale logistic regression and linear support vector machines using spark
PDF
Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
PDF
2014-06-20 Multinomial Logistic Regression with Apache Spark
PDF
Extending Spark SQL API with Easier to Use Array Types Operations with Marek ...
ODP
FOSS4G 2010 PostGIS Raster: an Open Source alternative to Oracle GeoRaster
PDF
Multinomial Logistic Regression with Apache Spark
PDF
Reactive Collections
Reducing the time of heuristic algorithms for the Symmetric TSP
Large scale logistic regression and linear support vector machines using spark
Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
2014-06-20 Multinomial Logistic Regression with Apache Spark
Extending Spark SQL API with Easier to Use Array Types Operations with Marek ...
FOSS4G 2010 PostGIS Raster: an Open Source alternative to Oracle GeoRaster
Multinomial Logistic Regression with Apache Spark
Reactive Collections

What's hot (16)

PDF
ICCSA 2010 Conference Presentation
PDF
Photo-realistic Single Image Super-resolution using a Generative Adversarial ...
PDF
ICISA 2010 Conference Presentation
PPTX
Scaling out logistic regression with Spark
PDF
Timing requirements
PDF
Gclogs j1
PDF
Practical and Worst-Case Efficient Apportionment
PDF
The Ring programming language version 1.4.1 book - Part 30 of 31
PPTX
Grill at bigdata-cloud conf
PDF
Data Profiling in Apache Calcite
PDF
The Ring programming language version 1.8 book - Part 84 of 202
PDF
Representing and Querying Geospatial Information in the Semantic Web
PPTX
Paris data-geeks-2013-03-28
PDF
Performance features12102 doag_2014
PPTX
The Weather of the Century Part 2: High Performance
DOCX
Lab 3 nust control
ICCSA 2010 Conference Presentation
Photo-realistic Single Image Super-resolution using a Generative Adversarial ...
ICISA 2010 Conference Presentation
Scaling out logistic regression with Spark
Timing requirements
Gclogs j1
Practical and Worst-Case Efficient Apportionment
The Ring programming language version 1.4.1 book - Part 30 of 31
Grill at bigdata-cloud conf
Data Profiling in Apache Calcite
The Ring programming language version 1.8 book - Part 84 of 202
Representing and Querying Geospatial Information in the Semantic Web
Paris data-geeks-2013-03-28
Performance features12102 doag_2014
The Weather of the Century Part 2: High Performance
Lab 3 nust control
Ad

Viewers also liked (17)

DOCX
Garbage collector complete information
ODP
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
PPT
Java Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
PDF
Performance van Java 8 en verder - Jeroen Borgers
PDF
Java memory presentation
PDF
From Java code to Java heap: Understanding and optimizing your application's ...
PPT
Mark and sweep algorithm(garbage collector)
PDF
Understanding Java Garbage Collection
PPTX
Getting ready to java 8
PPTX
Memory Management: What You Need to Know When Moving to Java 8
PPTX
Garbage collection algorithms
PDF
50 new things you can do with java 8
KEY
3장. Garbage Collection
PPTX
55 New Features in Java SE 8
PPTX
What's New in Java 8
PDF
Java SE 8 best practices
PPTX
Java 8 Support at the JVM Level
Garbage collector complete information
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
Java Garbage Collectors – Moving to Java7 Garbage First (G1) Collector
Performance van Java 8 en verder - Jeroen Borgers
Java memory presentation
From Java code to Java heap: Understanding and optimizing your application's ...
Mark and sweep algorithm(garbage collector)
Understanding Java Garbage Collection
Getting ready to java 8
Memory Management: What You Need to Know When Moving to Java 8
Garbage collection algorithms
50 new things you can do with java 8
3장. Garbage Collection
55 New Features in Java SE 8
What's New in Java 8
Java SE 8 best practices
Java 8 Support at the JVM Level
Ad

Similar to Jvm heap (20)

PDF
JVM and Garbage Collection Tuning
PPT
«Большие объёмы данных и сборка мусора в Java
PPTX
A G1GC Saga-KCJUG.pptx
PDF
JVM Garbage Collection Tuning
PDF
Tuning IBMs Generational GC
PPTX
G1 Garbage Collector - Big Heaps and Low Pauses?
PDF
What you need to know about GC
ODP
Garbage Collection in Hotspot JVM
PPTX
Pick diamonds from garbage
PDF
Moving to G1GC
PDF
Basics of JVM Tuning
PPTX
Garbage collection Overview
PPTX
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
PDF
Low latency Java apps
PDF
Java at Scale, Dallas JUG, October 2013
PPTX
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
ODP
Gc algorithms
PDF
Performance Tuning - Understanding Garbage Collection
PDF
Java 9: The (G1) GC Awakens!
PPTX
JVM @ Taobao - QCon Hangzhou 2011
JVM and Garbage Collection Tuning
«Большие объёмы данных и сборка мусора в Java
A G1GC Saga-KCJUG.pptx
JVM Garbage Collection Tuning
Tuning IBMs Generational GC
G1 Garbage Collector - Big Heaps and Low Pauses?
What you need to know about GC
Garbage Collection in Hotspot JVM
Pick diamonds from garbage
Moving to G1GC
Basics of JVM Tuning
Garbage collection Overview
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Low latency Java apps
Java at Scale, Dallas JUG, October 2013
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Gc algorithms
Performance Tuning - Understanding Garbage Collection
Java 9: The (G1) GC Awakens!
JVM @ Taobao - QCon Hangzhou 2011

More from Juarez Junior (20)

PDF
WeAreDevelopers Berlin - Blazingly Fast GenAI App Development With Java and S...
PDF
WeAreDevelopers Berlin - LangChain4J - A Guide for Impatient Developers
PDF
Build Stuff Lithuania - Blazingly Fast GenAI App Development With Java and Sp...
PDF
DUBJUG-Simplifying Data Access with Jakarta Data for Domain-Driven Design
PDF
Cloud Lunch and Learn -Microsoft Semantic Kernel for Java
PDF
Compass AI Budapest -The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
PDF
GSAS - Global Software Architecture Summit - GenAI-Architectural-Blueprints
PDF
BaselOne_Langchain4J - A Guide for Impatient Developers
PDF
DeveloperWeek USA - A Solid Foundation for GenAI Apps - Exploring Architectur...
PDF
I Love Tech Romania - Blazingly Fast GenAI App Development With Java and Spri...
PDF
I Love Tech Romania - The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
PDF
DUBJUG_Blazingly Fast GenAI App Development With Java and Spring AI.pdf
PDF
DUBJUG_Creating GenAI Apps in Java with SD4J and the ONNX Runtime
PDF
I Love Tech Romania - A High-Speed Data Ingestion Microservice in Java Using ...
PDF
DevTalks Cluj Romania - A Solid Foundation for GenAI Apps.pdf
PDF
Quarkus Club_Java Virtual Threads & Pipelined Database Operations
PDF
Quarkus Club_Revolutionize Java Database App Development with Reactive Stream...
PDF
TDC - The Developers Conference - The Trinity in GenAI - Spring AI, LangChain...
PDF
TDC - The Developers Conference - Creating GenAI Apps in Java with SD4J and t...
PDF
TDC - The Developers Conference - An Introduction to Machine Learning in Java...
WeAreDevelopers Berlin - Blazingly Fast GenAI App Development With Java and S...
WeAreDevelopers Berlin - LangChain4J - A Guide for Impatient Developers
Build Stuff Lithuania - Blazingly Fast GenAI App Development With Java and Sp...
DUBJUG-Simplifying Data Access with Jakarta Data for Domain-Driven Design
Cloud Lunch and Learn -Microsoft Semantic Kernel for Java
Compass AI Budapest -The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
GSAS - Global Software Architecture Summit - GenAI-Architectural-Blueprints
BaselOne_Langchain4J - A Guide for Impatient Developers
DeveloperWeek USA - A Solid Foundation for GenAI Apps - Exploring Architectur...
I Love Tech Romania - Blazingly Fast GenAI App Development With Java and Spri...
I Love Tech Romania - The Trinity in GenAI - Spring AI, LangChain4J and OpenAI
DUBJUG_Blazingly Fast GenAI App Development With Java and Spring AI.pdf
DUBJUG_Creating GenAI Apps in Java with SD4J and the ONNX Runtime
I Love Tech Romania - A High-Speed Data Ingestion Microservice in Java Using ...
DevTalks Cluj Romania - A Solid Foundation for GenAI Apps.pdf
Quarkus Club_Java Virtual Threads & Pipelined Database Operations
Quarkus Club_Revolutionize Java Database App Development with Reactive Stream...
TDC - The Developers Conference - The Trinity in GenAI - Spring AI, LangChain...
TDC - The Developers Conference - Creating GenAI Apps in Java with SD4J and t...
TDC - The Developers Conference - An Introduction to Machine Learning in Java...

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
KodekX | Application Modernization Development
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Programs and apps: productivity, graphics, security and other tools
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KodekX | Application Modernization Development
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I

Jvm heap

  • 1. Java™ Garbage Collection Statistical Analysis 101. Juarez Junior System Architect – Unisys Global Outsourcing
  • 2. Agenda. Java Heap Management Simple Garbage Collection Statistics • Generating the Data • Isolating the Data • Graphing the Data • Interpreting the Data • Improving Performance Advanced Garbage Collection Statistics • Generate, Isolate, Graph, Interpret, Improve Java Command Line Arguments Recap
  • 3. Java Heap. Young Generation • Eden - Where new objects are created • Survivor spaces - Where garbage collector places objects that are still in use Old Generation • Where tenured objects are placed References • http://java.sun.com/docs/hotspot/gc/ (1.3.1) • http://java.sun.com/docs/hotspot/gc1.4.2/
  • 4. Minor Garbage Collection. Occurs when no room in eden for new object Marks all reachable objects in eden and “from” survivor space Copies those objects to “to” survivor space • Updates references accordingly • If “to” survivor space fills, overflows to old generation Resets allocation pointer to start of eden H A B C D E I E F G H G I Old Generation Eden From From To To Spaces
  • 5. Major Garbage Collection. Occurs when insufficient room in old generation to hold to-be- tenured objects during a minor collection • Pessimistic – need sufficient space to hold all object in young generation • Pre-calculated – Minor collection reachable object algorithm run to determine exactly now many objects will be tenured Mark and Compact • Reachable objects are marked • Marked objects are moved to one end of the old generation J K M M N O L O V W A B C D P Q R X S T U X E F G H I Old Generation Eden To From Spaces
  • 6. Agenda. Java Heap Management Simple Garbage Collection Statistics • Generating the Data • Isolating the Data • Graphing the Data • Interpreting the Data • Improving Performance Advanced Garbage Collection Statistics • Generate, Isolate, Graph, Interpret, Improve Java Command Line Arguments Recap
  • 7. Generating Simple GC Data. -verbose:gc command line option java ... –verbose:gc ... my.java.app ... Results: ... [GC 1860K->1388K(1984K), 0.0005059 secs] Minor [GC 1900K->1446K(1984K), 0.0006679 secs] collections [GC 1958K->1468K(2112K), 0.0006251 secs] [Full GC 1468K-> 195K(2112K), 0.0131045 secs] Major and ... Time it took minor collection Total heap size Heap in use after collection Heap in use before collection
  • 8. Isolating the Simple GC Data. ... ... [GC 1860K->1388K(1984K), 0.0005059 secs] [GC 1900K->1446K(1984K), 0.0006679 secs] 1860,1388,0.0005059 [GC [Full GC 1958K->1468K(2112K), 1468K-> 195K(2112K), 0.0006251 0.0131045 secs] secs] Analyzer 1900,1446,0.0006679 ... 1958,1468,0.0006251 1468,195,0.0131045 ... import java.util.regex.Matcher; Comma-separated import java.util.regex.Pattern; value (CSV) file ... Pattern p = Pattern.compile ("[(?:Full |)GC (d*)K->(d*)K(d*K), ([d.]*) secs]"); Matcher m = p.matcher(simple_gc_data_output); while (m.find()) fout.println(m.group(1) + "," + m.group(2) + "," + m.group(3));
  • 9. Interpreting the Regular Expression. The ’’ char is an escape character, both in Java and in regular expressions. [(?:Full |)GC (d*)K->(d*)K(d*K), ([d.]*) secs] [(?:Full |)GC - match literal ‘[Full GC ’ or ‘[GC ’ (d*)K-> - capture all digits before the literal text ‘K->’ (d*)K - capture all digits before the literal text ‘K’ (d*K) - discard the digits and literal text ‘K’ within parenthesis - capture all digits and decimal point after the , ([d.]*) secs] comma and space, and before the literal text ‘secs]’ [Full GC 1468K-> 195K(2112K), 0.0131045 secs]
  • 10. Graphing the Simple GC Data. Load the CSV file into a spreadsheet Sum the third column - total time spent on GC Create fourth column • Third column * 10000 (or 100000) • Gets times within range of columns 1 and 2 Create a graph containing columns 1, 2 and 4.
  • 11. Graphing in Excel. Select first column only Create an “XY (Scatter)” graph Wizard step 2, click Series tab and add columns 2 and 4 to the series. • Click Add • Name: Type or select row 1 cell • X Values: leave empty • Y Values: Select cells in column Suggest creating new sheet for the chart
  • 12. Graphing in StarOffice. Swap the 3rd and 4th columns (seconds*10000 is now the 3rd column) Select the first 3 columns and create chart • Put chart in new sheet • Select ‘lines’ chart type • Select ‘normal’ variant After chart is created • Turn off labels on the X axis • Change width of data series lines to 0.02” or higher.
  • 13. Interpreting Graphed GC Data. Typical GC data graph For many GCs, the heap slowly fills as objects get moved to the old generation • Blue (or magenta) lines with positive slope Then a full GC happens • Drop in blue (or magenta) lines • Yellow dot in higher position
  • 14. Interpreting Graphed GC Data. Three Phases Phase 1 Phase 2 Phase 3 Phase 1 • Working set equilibrium • Ideal graph • No full GC Phase 2 • Full GC with heap not full - High GC times (yellow dots above blue zig-zag) • App called System.GC() Phase 3 • Incremental working set equilibrium • Implies various sub-phases each of which adds to working set
  • 15. Improving Performance, Before. Goal: 1000 business transactions in 12 minutes Heap set to: -Xms1024m –Xmx1024m 18 minute run, 472 seconds (7.8 minutes) in garbage collection Each GC is freeing very little memory
  • 16. Improving Performance, After. -Xms1024m –Xmx1024m -XX:NewSize=300m –XX:MaxNewSize=300m 12 minute run, 25 seconds in garbage collection • 70 collections instead of 8000 (no major/full collections) • Average collection freed 240MB instead of just 1MB
  • 17. Agenda. Java Heap Management Simple Garbage Collection Statistics • Generating the Data • Isolating the Data • Graphing the Data • Interpreting the Data • Improving Performance Advanced Garbage Collection Statistics • Generate, Isolate, Graph, Interpret, Improve Java Command Line Arguments Recap
  • 18. More GC Data. PrintGCDetails command line option java ... –XX:+PrintGCDetails ... my.java.app ... Results: Minor [GC [DefNew: 17131K->1606K(18432K), 0.0082055 secs] collection 44904K->29379K(63488K), 0.0083625 secs] [GC [DefNew: 17990K->17990K(18432K), 0.0000839 secs] [Tenured: 27772K->3759K(45056K), 0.0454394 secs] Major and 45763K->3759K(63488K), 0.0459597 secs] minor collection Time it took Heap size Sizes are for young Heap in use after collection generation, old generation, and total heap Heap in use before collection
  • 19. And Even More GC Data. PrintHeapAtGC command line option • java ... –XX:+PrintHeapAtGC ... my.java.app ... Results: {Heap before GC invocations=422: Heap def new generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: Heap def new generation total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) }
  • 20. PrintHeapAtGC Data. {Heap before GC invocations=422: Heap def new generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: Heap def new generation total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, Data from before GC 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) }
  • 21. PrintHeapAtGC Data. {Heap before GC invocations=422: Heap def new generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, Data from after GC 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: Heap def new generation total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) }
  • 22. PrintHeapAtGC Data. {Heap before GC invocations=422: Heap def new generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) Memory tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) addresses: the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) Memory compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) -addresses start the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: - next Heap - end def new generation eden space 16384K, total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) }
  • 23. PrintHeapAtGC Data. {Heap before GC invocations=422: Heap def new generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) Before GC, eden ‘next’ tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) pointer is at end compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: Heap def new generation total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) After GC, eden ‘next’ compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) } pointer is at start the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000)
  • 24. PrintHeapAtGC Data. {Heap before GC invocations=422: Heap def new generation For each generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: Memory in use Heap def new generation total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) Memory allocated compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) }
  • 25. PrintHeapAtGC Data. {Heap before GC invocations=422: Heap For each generational sub-space def new generation total 18432K, used 17639K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 100% used [0x6eb40000, 0x6fb40000, 0x6fb40000) from space 2048K, 61% used [0x6fd40000, 0x6fe79df8, 0x6ff40000) to space 2048K, 0% used [0x6fb40000, 0x6fb40000, 0x6fd40000) tenured generation total 45056K, used 6403K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70580f78, 0x70581000, 0x72b40000) Percentage of that compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) Heap after GC invocations=423: memory that is in use Heap def new generation total 18432K, used 1197K [0x6eb40000, 0x6ff40000, 0x6ff40000) eden space 16384K, 0% used [0x6eb40000, 0x6eb40000, 0x6fb40000) from space 2048K, 58% used [0x6fb40000, 0x6fc6b4e8, 0x6fd40000) to space 2048K, 0% used [0x6fd40000, 0x6fd40000, 0x6ff40000) tenured generation Amount of memory allocated total 45056K, used 6416K [0x6ff40000, 0x72b40000, 0x72b40000) the space 45056K, 14% used [0x6ff40000, 0x70584190, 0x70584200, 0x72b40000) compacting perm gen total 8192K, used 1597K [0x72b40000, 0x73340000, 0x76b40000) the space 8192K, 19% used [0x72b40000, 0x72ccf598, 0x72ccf600, 0x73340000) }
  • 26. Isolating the Data. Extract data • Need a very complex regular expression • CSV file, spreadsheet, with many columns Interesting data • Memory in use by each generation - Before and after each collection • Percent in use of “from space” New data - NOTE: “After” data same as next “Before” data worth graphing
  • 27. Graphing and Analyzing the Data. “From Space” usage is between 10% and 60% Adjust from space size using SurvivorRatio option • -XX:SurvivorRatio=ratio • Eden-size = survivor-size * ratio • Eden-size + 2 * survivor-ratio = young-gen- size Example: • -XX:NewSize=200M –XX:SurvivorRatio=8 • Eden: 160MB, each Survivor Space: 20MB Aim for 90-95% usage after collection • Typically, with large young generations, use larger ratio (e.g. 32)
  • 28. Agenda. Java Heap Management Simple Garbage Collection Statistics • Generating the Data • Isolating the Data • Graphing the Data • Interpreting the Data • Improving Performance Advanced Garbage Collection Statistics • Generate, Isolate, Graph, Interpret, Improve Java Command Line Arguments Recap
  • 29. Garbage Collection Info Options. -verbose:gc • Heap usage before and after GC • Time spent during GC -XX:+ PrintGCDetails • Generation and heap size before and after GC • Time spent during GC -XX:+ PrintHeapAtGC • Generation sizes before and after GC • Space sizes and percent in use before and after GC • Memory locations of the heap, its generations, and their spaces
  • 30. Java Tuning Options. -Xmssizem, -Xmxsizem • Minimum and maximum heap size • Set both sizes to the same value -XX:NewSize=sizem, -XX:MaxNewSize=sizem • Minimum and maximum young generation size • Set both sizes to the same value • Set to about 1/3 or 1/4 the size of the heap. -XX:SurvivorRatio=ratio • Number of times the eden space is larger than the “from” space • Try for maximum of 90-95% usage
  • 31. Conclusions. The HotSpot™ JVM provides a variety of options for gathering garbage collection statistics. Those statistics are easily extracted using • A simple Java application using • A regular expression The extracted data is easily graphed using a spreadsheet application. Examining the resulting graph • Tells a lot about what the application is doing • Enables selection of proper heap sizing to improve performance of the application.