gpt4 book ai didi

java - 我如何计算出 ehcache 使用了多少内存?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:57 26 4
gpt4 key购买 nike

我正在使用 JBoss 7.1.3.AS 和 Java 6 以及这个版本的 ehcache

            <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.1.0.Final</version>
</dependency>

我们在 Amazon Linux 上运行。如何确定我的 ehcache 使用了多少内存?我可以看到有关 JBOss 使用 top 的统计信息......

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND   
12159 jboss 20 0 14.9g 5.7g 25m S 163.2 19.3 225:18.15 java

以及我们系统上有多少空闲内存......

[dalvarado@east1c ~]$ free -m
total used free shared buffers cached
Mem: 30104 8099 22004 0 161 1859
-/+ buffers/cache: 6078 24026
Swap: 0 0 0

但我有兴趣弄清楚我们的 ehcache 具体使用了多少内存,以便我们可以调整默认缓存中条目的数量。请注意,因为我们处于生产环境中,所以添加新的 Java 代码不是立即的选择。下面是 ehcache 配置……

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false">

<!-- This is a default configuration for 256Mb of cached data using the JVM's heap, but it must be adjusted
according to specific requirement and heap sizes -->
<defaultCache maxElementsInMemory="200000"
eternal="false"
timeToIdleSeconds="86400"
timeToLiveSeconds="86400"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU">
</defaultCache>
<cache name="main" maxElementsInMemory="200000" />

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=32"/>

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=40001,
socketTimeoutMillis=2000"/>

</ehcache>

最佳答案

如果您被允许对正在运行的 Java 应用程序进行堆转储,请使用内存分析器对其进行分析,例如使用 MAT http://www.eclipse.org/mat/

要进行堆转储,您可以使用jmap。识别您的 java 进程的 pid,例如使用

ps aux |grep java

然后

jmap -dump:format=b,file=heap_dump.hprof <pid>

用 MAT 打开文件 heap_dump.hprof

Memory Analyzer 提供了对象图的支配树,因此您可以选择ehcache 缓存对象作为根,并详细查看子缓存对象。

关于java - 我如何计算出 ehcache 使用了多少内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41169951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com