如何跟踪和监控 JVM 类大小

huangapple go评论75阅读模式
英文:

How to track and monitoring, jvm class size

问题

昨天我的JVM应用程序因CPU使用率过高而出现故障,检查根本原因是因为GC暂停了应用程序。GC需要更多的时间来清理内存,这是因为我在应用程序中引入了新的LRU缓存。所以我的问题是:

是否有办法跟踪每个JVM类别的内存使用情况?例如,我有3个类,FooBarBaz

我想知道每个类在运行时使用了多少内存。

我有一个Datadog账户,所以我计划使用工具将这些指标发送到Datadog。

英文:

Yesterday my JVM application was broken due to high CPU usage, when checking the root cause this is because GC stop the world. The GC require more time to clean up the memory, this is because I introduce new LRU cache at the app. So my question is:

Is there any way to track how big memory group by JVM class? For example, I have 3 classes, Foo, Bar, Baz.

I want to know how big memory used by each class at run time.

I have a Datadog account, so I plan to use tools to send those metrics to Datadog.

答案1

得分: 2

你可以使用简单的 jcmd 命令行工具

jcmd <PID> GC.class_histogram | less

以下是在我的简单Clojure应用程序上运行此命令的示例:

 num     #instances         #bytes  class name (module)
-------------------------------------------------------
   1:         40131        2944504  [B (java.base@14.0.1)
   2:         38953        1666008  [Ljava.lang.Object; (java.base@14.0.1)
   3:          7610         961920  java.lang.Class (java.base@14.0.1)
   4:         36134         867216  java.lang.String (java.base@14.0.1)
   5:          2353         762216  [I (java.base@14.0.1)
   6:         25076         601824  clojure.lang.PersistentHashMap$BitmapIndexedNode
   7:         13950         446400  java.util.concurrent.ConcurrentHashMap$Node (java.base@14.0.1)
...
英文:

You can use simple jcmd command line tool

jcmd &lt;PID&gt; GC.class_histogram | less

As an example of running this on my simple Clojure application:

 num     #instances         #bytes  class name (module)
-------------------------------------------------------
   1:         40131        2944504  [B (java.base@14.0.1)
   2:         38953        1666008  [Ljava.lang.Object; (java.base@14.0.1)
   3:          7610         961920  java.lang.Class (java.base@14.0.1)
   4:         36134         867216  java.lang.String (java.base@14.0.1)
   5:          2353         762216  [I (java.base@14.0.1)
   6:         25076         601824  clojure.lang.PersistentHashMap$BitmapIndexedNode
   7:         13950         446400  java.util.concurrent.ConcurrentHashMap$Node (java.base@14.0.1)
...

huangapple
  • 本文由 发表于 2020年7月23日 20:44:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63054587.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定