JobHarvest——虚拟机性能监控实例

工具的介绍来自《深入理解JAVA虚拟机》4.2章

本文分别介绍了jdk中的一些常用虚拟机工具,然后对JobHarvest系统进行性能监控,最终得出一些简单的总结

工具概述 

Jps监控

  

$ jps -l
6280 sun.tools.jps.Jps
9028 org.jetbrains.jps.cmdline.Launcher
7132 com.intellij.rt.execution.application.AppMain
13684


分析:因为是在IDEA运行的程序,所以主类的全名应该是com.intellij.rt.execution.application.AppMain,可以看到jobHarvestvim是7132

 jstat


实测

jstat -gcutil 6064 250 20

250ms为周期统计一次,共统计20

  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
  0.00  98.20  91.03  28.17  98.02     11    0.211     0    0.000    0.211
  0.00  98.20  93.40  28.17  98.02     11    0.211     0    0.000    0.211
  0.00  98.20  94.20  28.17  98.02     11    0.211     0    0.000    0.211
  0.00  98.20  96.72  28.17  98.02     11    0.211     0    0.000    0.211
  0.00  98.20  98.50  28.17  98.02     11    0.211     0    0.000    0.211
  0.00  98.20  99.21  28.17  98.02     11    0.211     0    0.000    0.211
 97.14   0.00   1.26  28.50  98.02     12    0.229     0    0.000    0.229
 97.14   0.00   2.10  28.50  98.02     12    0.229     0    0.000    0.229
 97.14   0.00   3.29  28.50  98.02     12    0.229     0    0.000    0.229


分析

S1S1)区使用了98%的区域,eden区(E)使用了91%的区域,老年区(O)使用了28%的区域,方法区(P)使用了98%的区域,年轻代GCYGC)执行11次,耗时(YGCT0.211sFGC 0次,总GCGCT)耗时0.211s

Jmap使用

 

 

显示堆中对象统计信息,包括类、实例数量和合计容量

实测

jmap -histo 9056 |grep bbscraw

 419:            26           1248  com.leocai.bbscraw.beans.JobInfo
 551:            10            320  com.leocai.bbscraw.beans.JobInfoIndex
 707:             5            120  com.leocai.bbscraw.services.impl.CrawlerServiceImpl$1

生成堆转储快照:

jmap -dump:format=b,file=d://jobharvest.bin  9056
Dumping heap to D:\jobharvest.bin ...
Heap dump file created

分析

利用VisualVMdump文件信息(VisualVM是一个强大的检测工具,以后有空再介绍哈)

 

 

看到大部分都是Char[]的实例

再看看里面的内容是啥

 

应该是爬取网页中的一些http头信息,以及网页内容信息

Jhat


实测

jhat d://jobharvest.bin
Reading from d://jobharvest.bin...
Dump file created Sun Aug 07 16:34:04 CST 2016
Snapshot read, resolving...
Resolving 1444647 objects...
Chasing references, expect 288 dots................................................................................................................................................................................................................................................................................................
Eliminating duplicate references................................................................................................................................................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

分析

在浏览器里输入:localhost7000后,会出现jhat页面

 

Hist Histogram同样可以看到类实例的统计信息

 

点进某个类后可以考到其中实例的内容:

 

 jstak

 

实测

Grep -C 15代表查找目标前后15行,--color=auto高亮显示

jstack -l 8480|grep -C 15 --color=auto leocai
      
"Forwarding getElementText on session 0957c6c3-fbe1-4a1c-981c-d4ffcc5b04c2 to remote" prio=6 tid=0x000000000cc2e000 nid=0x24a8 runnable [0x000000000e4fe000]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:152)
        at java.net.SocketInputStream.read(SocketInputStream.java:122)
        at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
        at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
--
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
        at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:144)
        at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:160)
        at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:380)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
        at org.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:179)
        at com.leocai.bbscraw.crawlers.MyCrawler.crawSince(MyCrawler.java:89)
        at com.leocai.bbscraw.services.impl.CrawlerServiceImpl$1.call(CrawlerServiceImpl.java:110)
        at com.leocai.bbscraw.services.impl.CrawlerServiceImpl$1.call(CrawlerServiceImpl.java:105)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
 
   Locked ownable synchronizers:
        - <0x00000007ddbb3c08> (a java.util.concurrent.ThreadPoolExecutor$Worker)
 
"pool-1-thread-3" prio=6 tid=0x000000000d9dc800 nid=0x1964 runnable [0x000000000eabe000]
   java.lang.Thread.State: RUNNABLE
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        - locked <0x00000007d8a416d0> (a java.net.DualStackPlainSocketImpl)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
--
        - locked <0x00000007d8a41590> (a sun.net.www.http.HttpClient)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
        at sun.net.www.http.HttpClient.New(HttpClient.java:308)
        at sun.net.www.http.HttpClient.New(HttpClient.java:326)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:997)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:933)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:851)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.isConnected(NewProfileExtensionConnection.java:220)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:110)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
        at com.leocai.bbscraw.crawlers.MyCrawler.init(MyCrawler.java:55)
        at com.leocai.bbscraw.crawlers.MyCrawler.crawSince(MyCrawler.java:83)
        at com.leocai.bbscraw.services.impl.CrawlerServiceImpl$1.call(CrawlerServiceImpl.java:110)
        at com.leocai.bbscraw.services.impl.CrawlerServiceImpl$1.call(CrawlerServiceImpl.java:105)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
 
   Locked ownable synchronizers:
        - <0x00000007ddbb3240> (a java.util.concurrent.ThreadPoolExecutor$Worker)
 
 
"Abandoned connection cleanup thread" daemon prio=6 tid=0x000000000d277000 nid=0x1988 in Object.wait() [0x000000000e68f000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000078166b4b8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
        - locked <0x000000078166b4b8> (a java.lang.ref.ReferenceQueue$Lock)
        at com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41)
--
        - waiting on <0x000000078170c3a0> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:503)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
        - locked <0x000000078170c3a0> (a java.lang.ref.Reference$Lock)
 
   Locked ownable synchronizers:
        - None
 
"main" prio=6 tid=0x000000000035e800 nid=0x2018 waiting on condition [0x00000000022ce000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000007ddbd0de8> (a java.util.concurrent.FutureTask)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
        at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:425)
        at java.util.concurrent.FutureTask.get(FutureTask.java:187)
        at com.leocai.bbscraw.services.impl.CrawlerServiceImpl.continueCraw(CrawlerServiceImpl.java:119)
        at com.leocai.bbscraw.CrawlerWriter.start(CrawlerWriter.java:31)
        at com.leocai.bbscraw.CrawlerWriter.main(CrawlerWriter.java:23)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
 
   Locked ownable synchronizers:
        - None
 
"VM Thread" prio=10 tid=0x000000000aa91000 nid=0x9c0 runnable
 
"GC task thread#0 (ParallelGC)" prio=6 tid=0x00000000020d0000 nid=0x1488 runnable
 
"GC task thread#1 (ParallelGC)" prio=6 tid=0x00000000020d2000 nid=0x1120 runnable


分析

1.状态:WAITINGTIME_WATINGRUNNABLE

· NEW - this state represents a new thread which is not yet started.

· RUNNABLE - this state represents a thread which is executing in the underlying JVM. Here executing in JVM doesn't mean that the thread is always executing in the OS as well - it may wait for a resource from the Operating system like the processor while being in this state.

· BLOCKED - this state represents a thread which has been blocked and is waiting for a moniotor to enter/re-enter a synchronized block/method. A thread gets into this state after calling Object.wait method.

· WAITING - this state represnts a thread in the waiting state and this wait is over only when some other thread performs some appropriate action. A thread can get into this state either by calling - Object.wait (without timeout), Thread.join (without timeout), or LockSupport.park methods.

· TIMED_WAITING - this state represents a thread which is required to wait at max for a specified time limit. A thread can get into this state by calling either of these methods:Thread.sleepObject.wait (with timeout specified), Thread.join (with timeout specified), LockSupport.parkNanosLockSupport.parkUntil

· TERMINATED - this state reprents a thread which has completed its execution either by returning from the run() method after completing the execution OR by throwing an exception which propagated from the run() method and hence caused the termination of the thread.

2.可以看到main线程状态是waitingwaiting的内容是futureTask

3.可以找到线程池的线程信息pool-1-thread-3


JobHarvest性能监控总结:

  1. jstat 查看gc后发现,YGC还是比较频繁的
  2. jmap生成堆转储文件还是很有用的,需要配合visualVM进行分析,可以查到对象用的比较多的都是什么
  3. jobharvest项目中字符串对象最多,内存大部分消耗在字符串上
  4. jstack也可以查看线程是否发生死锁


发布了35 篇原创文章 · 获赞 61 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/cql342624757/article/details/52143683