Java memory problem cases solutions

3,125
-1

Published on

share the common java memory problem cases solutions,including:
1. java.lang.OutOfMemoryError
2. full gc frequently
3. cms gc error: promotion failed or concurrent mode failure

Published in: Technology, News & Politics
4 Comments
15 Likes
Statistics
Notes
  • If you're interested in realtime garbage collection monitoring you can use this free VisualVM plugin: http://www.spyglasstools.com/documentation/spyglass-garbage-collector-analyzer/
    You can see many of presented concept on your own systems.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • awesome info. thanks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • thinks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thanks for sharing
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,125
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
175
Comments
4
Likes
15
Embeds 0
No embeds

No notes for slide

Java memory problem cases solutions

  1. 1. bluedavy2012-03
  2. 2.  Java Runtime Data Area -Xss Local Vars Native method Stack Operator -XX:PermSize – PC Method Area XX:MaxPermSize Stack Frame Method Stack Heap -Xms -Xmx
  3. 3.  Oracle JDK Java Heap -Xmn New Generation Eden S0 S1 Old Generation -XX:SurvivorRatio
  4. 4.  Oracle JDK startup options for memory manage  -Xms –Xmx –Xmn –XX:PermSize –XX:MaxPermSize  -XX:SurvivorRatio  -XX:+UseParallelGC || -XX:+UseParallelOldGC ▪ -XX:MaxTenuringThreshold -XX:ParallelGCThreads ▪ -XX:-UseAdaptiveSizePolicy  -XX:+UseConcMarkSweepGC ▪ -XX:CMSInitiatingOccupancyFraction - XX:+UseCMSInitiatingOccupancyOnly  -XX:+DisableExplicitGC – XX:+ExplicitGCInvokesConcurrent
  5. 5.  Startup options or tools for memory problem solution  -XX:+PrintGCDateStamps –XX:+PrintGCDetails -Xloggc  -XX:+HeapDumpOnOutOfMemoryError  -XX:+HeapDumpBeforeFullGC  -XX:+PrintFlagsFinal(JDK 6u21+)  for CMS GC ▪ -XX:+PrintPromotionFailure -XX:+CMSDumpAtPromotionFailure  jinfo  jstat  jmap  MAT  btrace  google perf-tools
  6. 6.  OOM  java.lang.OutOfMemoryError: {$reason} Full GC Frequently CMS GC  promotion failed  concurrent mode failure
  7. 7. -Xms4g –Xmx4g –Xmn2560m
  8. 8. Then to find who use Deflater.init
  9. 9.  java.lang.OutOfMemoryError: {$reason}  GC overhead limit exceeded  Java Heap Space  Unable to create new native thread  PermGen Space  Direct buffer memory  request {} bytes for {}. Out of swap space?
  10. 10.  GC overhead limit exceeded Java Heap Space  if code didn’t catch OutOfMemoryError,thread will exit;  slow response or no response at all ▪ because gc did frequently Out of Swap  Java process crash
  11. 11.  GC overhead limit exceeded Java Heap Space  monitor app log & gc log  heap dump or jmap –histo|-dump when oom  mat analyze heap dump  app developer or btrace to find where cause
  12. 12.  Out of swap  crash log  google-perftools  then btrace to find where cause  ps: maybe u can try delete -XX:+DisableExplicitGC if exist,reason can be found in this link。
  13. 13.  use ThreadLocal carefully; limit Collection/StringBuilder etc. size; limit batch ops size; limit the data size return by database; avoid infinite loop;
  14. 14.  OOM  java.lang.OutOfMemoryError: {$reason} Full GC Frequently CMS GC  promotion failed  concurrent mode failure
  15. 15.  Most Cases  because memory consumes too much a special case  a special frequently GC Case
  16. 16.  slow response or no response at all
  17. 17.  According gc log to see if the reason is consuming too much memory  if yes then add -XX:+HeapDumpBeforeFullGC or write a shell file to dump memory when full gc;  if no then use pstack & source code to see why full gc executes;
  18. 18.  OOM  java.lang.OutOfMemoryError: {$reason} Full GC Frequently CMS GC  promotion failed  concurrent mode failure
  19. 19.  promotion failed Case I  363439.937: [Full GC 363439.938: [ParNew (promotion failed): 523840K->523840K(523840K), 0.3404490 secs] 1690606K->1712399K(1834560K), 0.3412880 secs]  Taobao JDK help to find the reason ▪ ==WARNNING== allocating large array: thread_id[0x00002aaac2d85800], thread_name[ajp-0.0.0.0-8009-48], array_size[782611408 bytes], array_length[195652847 elememts]
  20. 20.  promotion failed Case II  1768.432: [GC 1768.432: [ParNew (promotion failed): 1572827K->1572827K(1572864K), 0.2845480 secs]  1972.208: [CMS: 10545160K- >5853155K(14680064K), 8.5355320 secs] 12105682K->5853155K(16252928K), [CMS Perm : 20907K->20873K(34952K)], 212.3113910 secs] [Times: user=53.38 sys=22.45, real=212.28 secs]  because cms gc fragmention
  21. 21.  four cases  promotion failed case III ▪ because CMSInitiatingOccupancyFraction too high...  concurrent mode failure case I ▪ because CMSInitiatingOccupancyFraction too high...  concurrent mode failure case II ▪ because old gen is too small  concurrent mode failure case III ▪ because permgen
  22. 22.  CMS GC problem will cause serial full gc,so the app response time will be very slow...
  23. 23.  According gc log to see if the reason is because CMSInitiatingOccupancyFraction is too high,if yes then adjust the option; if no,then  promotion failed ▪ if because memory ran out,then dump memory; ▪ if because cms gc fragmention,currently we only can do is execute jmap –histo:live at regular time;  concurrent mode failure ▪ the same as promotion failed...
  24. 24.  OOM  java.lang.OutOfMemoryError: {$reason} Full GC频繁 CMS GC  promotion failed  concurrent mode failure
  25. 25.  Young GC slow CMS GC Concurrent-Mark causes app stop... ...
  1. A particular slide catching your eye?

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

×