Memory leak Resource 力 金 3-tier 見 Out of Memory( 不 ) Memory leak( 漏 ) 狀 Application Server Crash 理 Server 狀 Crash 類 JVM 說 例 行說 說 Memory leak Resource Out of Memory Memory leak Out of Memory 不論 Java heap Native Memory 不 Memory leak 不論 Java heap Native Memory Out of memory Java heap, Native memory and Process Size 了 Memory leak 了 JVM 理 Java heap JVM 來 Java objects Java heap 令 行列 參數 -Xmx heap size JVM Java heap Native Memory JVM 來 Native Memory Heap JVM - 1 - 力
thread GC java object Third party native module Native Memory. 例 native JDBC driver Native Memory Native Memory OS virtual process size 參數 -Xmx Java Heap 例 3GB Java Heap 1G Native Memory 2GB Process Size Process Size Java Heap Native Memory 行 32 理 4GB 若 4GB 留 ( 1~2GB) Windows 4GB 2GB 2GB 不 Windows /3GB 參數切 例 3GB 參 Microsoft http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ddtools/hh/ddt ools/bootini_1fcj.asp Red Hat AS 2.1 3GB 參 Process 不 Process 32 0 4GB 立 RAM Swap Space RAM Swap Space 行 Process Process 行 Process 不 - 2 - 力
Out of Memory 狀 JVM 什 Out of Memory in java heap JVM java heap 來 更 java objects JVM java out of memory JVM 更 java objects heap 塞 了 objects java heap 狀 java.lang.outofmemoryerror JVM 什 例 行 行 不 不 理 thread 行離 JVM( java thread dump 不 thread) WebLogic Server 狀 execute thread 錄 連 不 來 core health monitor thread WebLogic Server Out of Memory in native heap native memory JVM native out of memory Process Process size 行 RAM Swap Space. JVM 理 native out memory 錄 說 行 out of native memory 離 JVM module( libc Third party module) 理 native out of memory 狀 sigabort JVM JVM 離 JVM sigabort - 3 - 力
理 Java Out of Memory 1. verbose gc verbosegc 參數 令 列 Server GC / stdout/stderr 行 Full GC run: 行 full GC soft/weak/phantomly reachable 更 不 說 http://java.sun.com/developer/technicalarticles/alt/refobj full GC out of memory 來 GC ( JVM JVM Help message 了 ) [memory ] 7.160: GC 131072K->130052K (131072K) in 1057.359 ms 說 ( ) [memory ] <start>: GC <before>k-><after>k (<heap>k), <total> ms [memory ] <start> - start time of collection (seconds since jvm start) [memory ] <before> - memory used by objects before collection (KB) [memory ] <after> - memory used by objects after collection (KB) [memory ] <heap> - size of heap after collection (KB) [memory ] <total> - total time of collection (milliseconds) soft/weak/phantomly reachable objects GC generational verbose [memory ] 2.414: Nursery GC 31000K->20760K (75776K), 0.469 ms - 4 - 力
nursery GC( young GC) 行 objects nursery( young space) old space 不 更 generational JVM GC 不 java out of memory JVM bug Full compaction: JVM 度 裂 large objects java out of memory Java Objects 連 JVM large objects JVM full compaction 更 連 large objects Compaction objects(data) java heap memory 更 references objects JVM 不 objects GC verbose gc 裂 java out of memory 列 java heap out of memory 裂 [memory ] 8.162: GC 73043K->72989K (131072K) in 12.938 ms [memory ] 8.172: GC 72989K->72905K (131072K) in 12.000 ms [memory ] 8.182: GC 72905K->72580K (131072K) in 13.509 ms java.lang.outofmemoryerror max heap 128MB JVM out of memory 72580K Heap 率 55% 45%free heap 例 裂 out of memory JVM bug 聯 - 5 - 力
2. JVM JVM ( ) java out of memory 不 漏 java memory objects 更 heap memory caching caches java objects cache cache objects 數量 降 降 java heap 量 JAVA soft references softly reachable objects data caching JVM 行 out of heap 行 objects 裡 Heap objects 降 objects 例 HTTP session timeout 更 session objects Memory leaks memory leak 例 database connection pools connection pools JDBC statement resultset objects pool connection objects close() connection pool 若 connection 聯 statement/resultset objects java heap java heap 3. 不 兩 狀 JVMPI(JVM Profiler Interface) profiler Jprobe OptimizeIt Objects java heap 立 裡 料不 降 裡 不 - 6 - 力
For Native OOM Problem: 1. 列 verbosegc output to monitor the java heap usage. 了 java memory 立 java heap JVM 留 heap ( -Xmx 參數 java 令 列 ) 不 留 Jrockit 例 -verbose -verbosegc GC codegen 錄 Process virtual memory size JVM 行 out of native memory 了 不 process Windows 例 列 度 virtual process size: \ 行 perfmon OK Performance + : Process ( 不 processor) 數 : Virtual Bytes 例 : Select the JVM (java) instance, Unix Linux PID virtual memory size 令 ps p <PID> -o vsz. Linux java thread JVM instance process root java process PID root java process ps 令 -forest 參數 例 ps IU <user> --forst process ASCII 狀 狀 root java - 7 - 力
2. RAM swap space 不 更 process out of memory RAM swap space 行 Process 3. Java heap java heap max heap 降 max heap 更 native memory JVM 不 process java heap native heap 4. JVM Native memory 量 classes JVM Native memory 量 (code ) JVM 行 class code native memory 了 行 不 jrockit 例 參數 -Xnoopt 行 SUN JVM 參數 -Xint JVM 行 interpreted mode(no code generation) 行 native memory 量 native code 5. Third party native modules JNI code 不論 Third party native module database driver native modules native memory 漏洞 modules 不 driver 例 pure java drivers native database drivers JNI native memory 漏 行 量不 JNI - 8 - 力
6. native memory JVM native memory 更 JVM 漏 論 out of memory GC 不 理 JDK Memory leak 行說 了 說 參 類 不 參 料 Investigating Out Of Memory / Memory Leak Problems http://support.bea.com/support_news/product_troubleshooting/investigating_out_of_ Memory_Memory_Leak_Pattern.html - 9 - 力