Excesive number of Timers
jorgemoralespou_2 Jul 2, 2007 5:36 AMHi,
I have JBC 1.4.1.SP3 in a JBossAS 4.2.0.
Cache configuration is this:
<?xml version="1.0" encoding="UTF-8"?> <server> <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/> <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=ServicesCache"> <depends>jboss:service=Naming</depends> <depends>jboss:service=TransactionManager</depends> <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute> <attribute name="IsolationLevel">NONE</attribute> <attribute name="CacheMode">REPL_SYNC</attribute> <attribute name="UseReplQueue">false</attribute> <attribute name="ReplQueueInterval">0</attribute> <attribute name="ReplQueueMaxElements">0</attribute> <attribute name="ClusterName">ServicesCache-Cluster</attribute> <attribute name="ClusterConfig"> <config> .... jgroups config ..... </config> </attribute> <attribute name="FetchInMemoryState">true</attribute> <attribute name="InitialStateRetrievalTimeout">15000</attribute> <attribute name="SyncReplTimeout">15000</attribute> <attribute name="LockAcquisitionTimeout">10000</attribute> <attribute name="EvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</attribute> <attribute name="EvictionPolicyConfig"> <config> <attribute name="wakeUpIntervalSeconds">5</attribute> <region name="/_default_"> <attribute name="maxNodes">500000</attribute> <attribute name="timeToLiveSeconds">86400</attribute> </region> </config> </attribute> <attribute name="UseRegionBasedMarshalling">true</attribute> <attribute name="InactiveOnStartup">true</attribute> </mbean> </server>
Later, in our application, through code we set different eviction policies for different regions, in order to keep a rational cache size ratio.
We do this to activate regions of the cache, as we deploy services that use these regions:
public void activateRegion(String strFqn) { try { RegionManager regionManager = getServiceCacheInstance() .getRegionManager(); if (regionManager.getRegion(strFqn) == null || !regionManager.getRegion(strFqn).isActive()) { getServiceCacheInstance().registerClassLoader(strFqn, Thread.currentThread().getContextClassLoader()); getServiceCacheInstance().activateRegion(strFqn); log.warn("Activating synchronization of region " + strFqn); } } catch (RegionNameConflictException e) { log.error("Activating region: " + strFqn, e); } catch (CacheException e) { log.error("Activating region: " + strFqn, e); } }
We also activate/deactivate different eviction policies for these regions. Like this:
public void activateEvictionPolicy(String strRegion, EvictionConfiguration config) { if (strRegion != null || "".equals(strRegion)) { RegionManager regionMgr = getServiceCacheInstance().getEvictionRegionManager(); Region region; EvictionPolicy eviction = null; try { if (regionMgr.hasRegion(strRegion)) { region = regionMgr.getRegion(strRegion); region.setEvictionConfiguration(config); log.warn("Region " + strRegion + " already had an eviction policy that has been updated now"); } else { eviction.configure(getServiceCacheInstance()); regionMgr.createRegion(strRegion, eviction, config); log.warn("Created new region " + strRegion); } log.warn("Setting "+ evictionPolicy.getType().toString()+ " eviction policy to region " + strRegion + ". Details: " + evictionPolicy); } catch (org.jboss.cache.eviction.RegionNameConflictException e) { throw new MyCacheRuntimeException( "Region name conflict for " + strRegion + ". Impossible to set an eviction policy."); } } else { log.error("There is not any eviction policy provided for region " + strRegion); } } }
My problem is:
The cache gets filled with about 2000 nodes, of 10 (key/value pairs) each, and for every node, I see there is a running Timer, which never gets discarded. At the end, my app fails being unable to create more threads.
I know this can be a memory problem, but I have set 1Gb heap, 384K thead size, and have a machine with 8Gb addresable memory, so my problem seems related to the number of threads being created.
For now, I only have one eviction policy set for one region, which holds the entire 2000 nodes, and I don understand why when a node gets evicted, or when most of them gets evicted, and node number drops to only 500, timers are over 2000.
Thanks.