Javaãã©ãã«ã«å¿ããåå対å¿ã®ã¾ã¨ã
Javaãã©ãã«ã§ã¯ãæ å ±ããªãã¦ãåç¾ããªããªããã¾ãããã¨ãã£ãç¶æ³ã«é¥ããã¨ãããããã®ãããªç¶æ³ãåé¿ããããã«ã以ä¸ã®3ã¤ã®ä»£è¡¨çãªãã©ãã«ãä¾ã«ãã¢ããªã±ã¼ã·ã§ã³ãµã¼ããåèµ·åããåã«ä½ãåå¾ããã°è¯ãã®ããã¾ã¨ãã¦ã¿ãã
- ã¢ããªã±ã¼ã·ã§ã³ããå¿çããªã
- ã¢ããªã±ã¼ã·ã§ã³ãé ã
- ãã¼ãã¡ã¢ãªã足ããªã(OutOfMemoryErrorã®çºç)
ã¢ããªã±ã¼ã·ã§ã³ããå¿çããªã
åå¾ããæ å ±
- ã¹ã¬ãããã³ã
ãã¼ã¿åå¾æ¹æ³
ã¹ã¬ãããã³ãã¨ã¯ãã³ãã³ãå®è¡æç¹ã§ã®Javaã¹ã¬ããå®è¡ç¶æ ãåºåãããã®ã§ãããå¿çããªãå ´åãä½ããã®è¦å ã«ããã©ããã§å¦çãæ¢ã¾ã£ã¦ãããã¨ãæ³å®ããããã¹ã¬ãããã³ãã¯ãã©ãã§æ¢ã¾ã£ã¦ããã®ãï¼ããåãåããã®ã«å¤§åãªæ å ±ã§ããã
åå¾æ¹æ³ã¯JDKã®ãã¼ã¸ã§ã³ã«ãã£ã¦è²ã ããã
- kill -3 <pid> (å°ãªãã¨ã1.4.2ã«ã¯ãããJDK7ã§ãæå¹)
- ${JAVA_HOME}/bin/jstack <pid> (JDK5/JDK6/JDK7)
- ${JAVA_HOME}/bin/jcmd <pid> Thread.print (JDK7)
ãããã®æä½ããJavaèµ·åããã»ã¹ã¨åãã¦ã¼ã¶ã§å®è¡ãããã¨ãkill -3 ã§åºåããå ´åã¯æ¨æºåºåã«ã¹ã¬ãããã³ããåºåããã¦ãã¾ãã®ã§ãè¥å¹²ä½¿ãåæãæªããjstackãjcmdã§åå¾ããã®ãå人çã«ãå§ãã
試ãã«ãWildfly8ã§ã³ãã¯ã·ã§ã³ãã¼ã«ãæ¯æ¸ããã¦ã³ãã¯ã·ã§ã³ã®åå¾å¾ ã¡ç¶æ ã«ãããã¹ã¬ãããã³ããåå¾ãã¦ã¿ãã
"default task-10" prio=5 tid=0x00007fef5bb8d000 nid=0xb307 waiting on condition [0x000000011090a000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x00000007fea15470> (a java.util.concurrent.Semaphore$FairSync) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226) ã çç¥ ã at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:142) at slowweb.SlowServlet.processRequest(SlowServlet.java:44) at slowweb.SlowServlet.doGet(SlowServlet.java:78) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
ãã©ãã«çºçæã«è¤æ°åã¹ã¬ãããã³ããçºçãã解æãã¼ã«ã§ããä¾ã«èªã¿è¾¼ã¾ãã¦ã¹ã¬ããç¶æ ã®é·ç§»ç¢ºèªãããã¨ãå¤ãã
ã¢ããªã±ã¼ã·ã§ã³ãé ã
åå¾ããæ å ±
- ãããã¡ã¤ã© (ãã¹ãç°å¢ã§åç¾ã§ããå ´å)
- ã¹ã¬ãããã³ã
ãã¼ã¿åå¾æ¹æ³
ãããã¡ã¤ã©ã«ã¤ãã¦ã¯ãç¡åã§ä½¿ããæ軽ãªJDKä»å±ã®hprofããããcpu=timeã«ããã¨é ããã¦æ å ±åéã«ãªããªãã®ã§ãcpu=sampleã§ãµã³ããªã³ã°ãããã¼ã¿ã§é常ã¯ååãhprofãèµ·åããã«ã¯ãJavaèµ·åãªãã·ã§ã³ã«"-agentlib:hprof=cpu=samples"ã追å ããã
è¨å®ä¾ã¯ä»¥ä¸ã®éãã
-agentlib:hprof=cpu=samples,file=/home/test/java.hprof
試ãã«Servletä¸ã§forã«ã¼ããããããåããç¶æ ã§hprofãå®è¡ãã¦ã¿ããsloweb.SlowServletãé ãåå ã¨ãã¦CPUæéã使ç¨ãã¦ãããã¨ãæµ®ãã³ä¸ãã£ã¦ããã
CPU SAMPLES BEGIN (total = 35772) Tue Mar 11 20:36:15 2014 rank self accum count trace method 1 91.91% 91.91% 32878 301280 sun.nio.ch.KQueueArrayWrapper.kevent0 2 2.47% 94.38% 882 300320 java.lang.ClassLoader.defineClass1 3 1.05% 95.43% 376 301958 slowweb.SlowServlet.processRequest 4 0.09% 95.52% 33 300506 java.io.FileInputStream.readBytes 5 0.08% 95.60% 29 300043 java.util.zip.ZipFile.open
ãã¼ãã¡ã¢ãªã足ããªã(OutOfMemoryErrorã®çºç)
åå¾ããæ å ±
- GCãã°
- ã¯ã©ã¹ãã¹ãã°ã©ã
- ãã¼ããã³ã
ãã¼ã¿åå¾æ¹æ³
GCãã°
GCãã°ãåå¾ãã¦ç¢ºèªããã¨ããã¼ãã¡ã¢ãªã足ããªããªã£ãåå ãããããããªä¸æããªã®ããæ¥æ¿ãªä¸æããåå ãªã®ãããããããããããªä¸æã§ãã£ãå ´åããªãã¸ã§ã¯ãåç §ã®è§£æ¾æ¼ããªã©ãåå ãªã®ã§è§£æã¯å°ãåä»ãæ¥æ¿ãªä¸æãè¦ãããå ´åã¯ãå¤ãã®å ´åDBããã¡ã¤ã«ããä¸åº¦ã«å¤§éã®ãã¼ã¿ãèªã¿è¾¼ãã ãã¨ãè¯ãããåå ã ããã
GCãã°ã¯ä»¥ä¸ã®Javaèµ·åãªãã·ã§ã³ã«ä»¥ä¸ã®ããã«è¨å®ãããã¨ã§åå¾ãããJDK6u34/JDK7u2ããã¯ãµã¤ãºãã¼ãã¼ã·ã§ã³æ©è½ããã£ã¦ä¾¿å©ãåå¾ããGCãã°ã¯GCViewerã使ã£ã¦ã°ã©ãåããã
-Xloggc:/home/test/wildfly-8.0.0.Final/standalone/log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=10M
åå¾å ãã¹(-Xloggc)ã¯ãAPãµã¼ãã®ãã°ãã£ã¬ã¯ããªã«è¨å®ããã¨ä¾¿å©ã
ã¯ã©ã¹ãã¹ãã°ã©ã
ã¯ã©ã¹ãã¹ãã°ã©ã ãåå¾ããã¨ããã¼ããå§è¿«ãã¦ããåå ã¯ã©ã¹ãè¦ãã¦ãããå¾è¿°ãããã¼ããã³ãã«æ¯ã¹è² è·ã軽ãã®ä¾¿å©ãªç¹ã ããåå¾ã«ä¼´ãFullGCçºçã«ã¯æ°ãã¤ããå¿ è¦ããããã¹ã¬ãããã³ãã¨åæ§ãJDK7ã®jcmdã®å°å ¥ã«ä¼´ãè¤æ°ã®ããæ¹ã§åå¾ãããã¨ãå¯è½ã
èµ·åä¸ã®NetBeansã«åãã¦å®è¡ãã¦ã¿ãã
num #instances #bytes class name ---------------------------------------------- 1: 25028 24122528 [B 2: 203992 22519616 [C 3: 199716 6390912 java.util.HashMap$Node
ãã¼ããã³ã
ã¯ã©ã¹ãã¹ãã°ã©ã ã§ã¯ãªãã¸ã§ã¯ãéã®åç §é¢ä¿ã¾ã§ã¯ç¢ºèªã§ããªãã®ã§ã誰ãåç §ãã¦ãã¦GCãããªãã®ãã調ã¹ããã¨ã¯ã§ããªãããã®ãããªå ´åããã¹ãç°å¢ã§åé¡ãåç¾ããã¦ãã¼ããã³ããåå¾ããããããªãã«éããã®ã§ãéç¨ç°å¢ã§å®è¡ãããã¨ã¯ãå§ãã§ããªãã
ãã¼ããã³ããåæ§ã«ãè¤æ°ã®ããæ¹ã§åå¾å¯è½ã
- ${JAVA_HOME}/bin/jmap -dump:live,format=b,file=dump.bin <pid>
ãã¼ããã³ãã®èªã¿è¾¼ã¿ãã¼ã«ã«ã¯JDKæ¨æºã®jhatãããããEclipse Memory Analyzerã使ããããã¨æãã
試ãã«åãã¦ããNetBeansã対象ã«ãã¼ããã³ããåå¾ãã¦Eclipse Memory Analyzerã«èªã¿è¾¼ã¾ãã¦ã¿ãã¨ã以ä¸ã®ããã«ãã¼ãä¸ã«å¤ããªãã¸ã§ã¯ãã®ææ(Leak Suspectsæ©è½)ãªã©ã確èªã§ããã
ã¾ã¨ã
- ã¢ããªã±ã¼ã·ã§ã³ããå¿çããªãæã¯ã¹ã¬ãããã³ã
- é ãã¨ãã¯ãããã¡ã¤ã«ã¨ã¹ã¬ãããã³ã
- Javaãã¼ãã¡ã¢ãªã足ããªããªã£ããGCãã°/ã¯ã©ã¹ãã¹ãã°ã©ã /ãã¼ããã³ã
ãã¡ãããå ¨ã¦ã®åé¡ããããã®æ å ±ã§è§£æ±ºã§ããããã§ã¯ãªãããåå対å¿ã¨ãã¦æä½éããã¨ä¾¿å©ãªæ å ±ã ã¨æãã
ã¾ããæè¿ã¯æåã®Java Flight RecorderãOSSã®HeapStatsãªã©ãã·ã¹ãã ãæ£å¸¸ã«åãã¦ããã¨ãããå°ããã¤æ å ±ãåå¾ãããã¼ã«ãåºã¦ãã¦ãããã¾ãã®æ©ä¼ã«ã¾ã¨ããäºå®ã