Results 1 to 6 of 6
  1. #1
    infinitiguy is offline Member
    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0

    Default Trying to monitor jvm for out of memory errors

    Hi,
    I'm looking to figure out an easy way to monitor a java process to see when heap usage gets over a certain threshold of the total max heap. This is how I've started my java process (jira) and jmap shows current stats. Ideally I'd like to be able to query and find out when I'm around 1.8gb of max heap (out of 2gb total). It looks like the percentages used change depending upon how much is allocated. I would also expect to see at least something around 1gb since that's what I set the initial heap size to.

    Can anyone give me any pointers? I've only just started playing with this stuff (jvm monitoring).

    [jira@jiraserver bin]$ ps -ef | grep java
    jira 23497 6289 0 12:50 pts/3 00:00:00 grep java
    jira 30317 1 0 Aug05 ? 00:08:12 /apps/software/java/jdk1.6.0_20//bin/java -Djava.util.logging.config.file=/apps/software/tomcat/jira/current/conf/logging.properties -XX:MaxPermSize=256m -Xms1024m -Xmx2048m -Djava.awt.headless=true -Datlassian.standalone=JIRA -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_B UFFER=true -Dmail.mime.decodeparameters=true -Djira.jelly.on=true -Djira.home=/apps/software/tomcat/jira/jirahome -Djava.util.logging.manager=org.apache.juli.ClassLo aderLogManager -Djava.endorsed.dirs=/apps/software/tomcat/jira/current/endorsed -classpath /apps/software/tomcat/jira/current/bin/bootstrap.jar -Dcatalina.base=/apps/software/tomcat/jira/current -Dcatalina.home=/apps/software/tomcat/jira/current -Djava.io.tmpdir=/apps/software/tomcat/jira/current/temp org.apache.catalina.startup.Bootstrap start
    [jira@jiraserver bin]$ ./jmap -heap 30317
    Attaching to process ID 30317, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 16.3-b01

    using thread-local object allocation.
    Parallel GC with 8 thread(s)

    Heap Configuration:
    MinHeapFreeRatio = 40
    MaxHeapFreeRatio = 70
    MaxHeapSize = 2147483648 (2048.0MB)
    NewSize = 5439488 (5.1875MB)
    MaxNewSize = 17592186044415 MB
    OldSize = 5439488 (5.1875MB)
    NewRatio = 2
    SurvivorRatio = 8
    PermSize = 21757952 (20.75MB)
    MaxPermSize = 268435456 (256.0MB)

    Heap Usage:
    PS Young Generation
    Eden Space:
    capacity = 349503488 (333.3125MB)
    used = 338399616 (322.7230224609375MB)
    free = 11103872 (10.5894775390625MB)
    96.82295817316707% used
    From Space:
    capacity = 4194304 (4.0MB)
    used = 1480624 (1.4120330810546875MB)
    free = 2713680 (2.5879669189453125MB)
    35.30082702636719% used
    To Space:
    capacity = 3932160 (3.75MB)
    used = 0 (0.0MB)
    free = 3932160 (3.75MB)
    0.0% used
    PS Old Generation
    capacity = 715849728 (682.6875MB)
    used = 419149776 (399.7323760986328MB)
    free = 296699952 (282.9551239013672MB)
    58.55276039163348% used
    PS Perm Generation
    capacity = 156434432 (149.1875MB)
    used = 156432376 (149.18553924560547MB)
    free = 2056 (0.00196075439453125MB)
    99.99868571134007% used

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,936
    Rep Power
    19

    Default

    You've got exactly what you said there.
    MaxHeapSize = 2147483648 (2048.0MB)
    ...
    Eden Space:
    capacity = 349503488 (333.3125MB)
    ...
    PS Old Generation
    capacity = 715849728 (682.6875MB)
    (that's about a GB for those two, so that's your Xms)

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,936
    Rep Power
    19

    Default

    Oh, and for polling you'll want to use Runtime.
    Memory used currently is totalMemory - freeMemory.

  4. #4
    infinitiguy is offline Member
    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0

    Default

    How would I use runtime? Can I call it against a specific pid? I'm not a java programmer, it looks like runtime would be a function I would need to reference inside of some java code.
    Regarding what I have below:
    You've got exactly what you said there.
    MaxHeapSize = 2147483648 (2048.0MB)
    ...
    Eden Space:
    capacity = 349503488 (333.3125MB)
    ...
    PS Old Generation
    capacity = 715849728 (682.6875MB)
    (that's about a GB for those two, so that's your Xms)

    Does that mean lets say total JVM usage grew to 2gb (Xmx), given the same usage ratios I might see something like:

    Eden Space:
    capacity = 689503488 (666.3125MB)
    used = 668399616 (642.7230224609375MB)
    free = 20103872 (20.5894775390625MB)
    96.82295817316707% used

    PS Old Generation
    capacity = 1415849728 (1382.6875MB)
    used = 819149776 (798.7323760986328MB)
    free = 598699952 (562.9551239013672MB)
    58.55276039163348% used

    Does Eden get moved into PS Old Gen when GC's are run? I can easily do calculations based off of the combination of eden/old permgen total cap vs used memory. Will that be an accurate way of knowing when the JVM could potentially be hitting OOM errors or are there other stats I should query as well?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,936
    Rep Power
    19

    Default

    Ah yes.
    For some reason I read your OP as doing this inside an existing app, rather than as monitoring an app.

    As for that memory stuff, pretty much. Not sure how the ratios move for Eden to Old. How gc is run is a rather large topic. Essentially, Eden is the new stuff, and gets swept through more often than the Old Gen. This lets shortlived objects get cleared out more frequently without having to do sweeps of things that are hanging around. When something survives x number of sweeps in Eden (and this is only a general precis, so don't take it as "the way it works") it gets promoted to the Old Gen.

    When you start to fill up then a full gc is run.

    You should be OK monitoring those two sets, though. To Space and From Space are too small to make much odds.
    PermGen is a bit pointless to monitor, unless you want to watch out for running out of that (ie lots of classes being loaded).

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,936
    Rep Power
    19

Similar Threads

  1. Replies: 1
    Last Post: 07-18-2011, 04:24 PM
  2. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  3. question about so-called "memory consistency errors"
    By gib65 in forum Threads and Synchronization
    Replies: 2
    Last Post: 06-20-2010, 04:20 PM
  4. Replies: 2
    Last Post: 08-21-2008, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •