2016-12-15 12 views
0

我使用JBoss 7.1.3.AS與Java 6這個版本的Ehcache如何判斷ehcache使用多少內存?

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

我們在Amazon Linux上運行的。如何確定ehcache使用的內存量?我可以看到多少JBoss的統計與頂部使用...

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 

以及有多少可用內存是在我們的系統...

[[email protected] ~]$ 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> 

回答

0

如果你被允許採取堆轉儲您運行Java應用程序,把它和內存分析器分析,例如與MAT http://www.eclipse.org/mat/

對於採取堆轉儲,你可以使用jmap。找出你的java進程的PID,例如用

ps aux |grep java 

,比

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

打開文件heap_dump.hprof與MAT。

內存分析器提供了對象圖的支配樹,因此您可以選擇ehcache緩存對象作爲根,並詳細查看子緩存對象。

+0

請包括做堆轉儲的insturctions。 – Dave

+0

@Dave,包括 – popalka

+0

感謝您的信息。可悲的是,當我運行「我發現了哪個jmap」時,我們沒有在我們的Amazon Linux實例上擁有那個jmap。有沒有其他的方式來獲得堆轉儲? – Dave

0

EhCache爲此提供了net.sf.ehcache.management.sampled.Sampled Cache。用JMX註冊它。除其他外,它公開了被註冊的緩存使用的字節堆。

創建它是很容易的,它只是包裝現有高速緩存:

SampledCache sampledCache = new SampledCache(cache); 

它暴露的數據量是非常有用的:API