views:

283

answers:

1

I'm trying to create a jboss-cache for data that is only relevant for a short period of time. After that time the data should be discarded and the respective memory freed.

The cache is organized like this:

/my_region
    /session_1
        /datanode_1
          attribute1: value1
        /datanode_2
          attribute2: value2
    /session_2
        ...
    /session_3
        ...
    ...
    ...

And my eviction policy configuration looks like this:

<attribute name="EvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</attribute> 
<attribute name="EvictionPolicyConfig">
   <config>
      <attribute name="wakeUpIntervalSeconds">5</attribute>     
         <region name="/my_region">
     <attribute name="maxNodes">100</attribute>
     <attribute name="timeToLiveSeconds">1800</attribute>
        </region>
   </config>
</attribute>

This works: when /my_region gets more than 100 children, the least recently used children are evicted so that the region shrinks back to 100 children.

The problem with the LRUPolicy is that when the evicted nodes have children, they're not completely removed, but marked with jboss:internal:uninitialized: null instead. This behaviour makes sense for entities that are cached to avoid fetching them from a persistent storage, but it is not suitable for caching entities that are not persisted and will never be accessed again.

So, to remove the nodes, I've created an extension of LRUPolicy that overrides evict with remove.

@Override
public void evict(Fqn fqn) throws Exception {
    cache_.remove(fqn);
}

This new policy does not leave joss:internal:uninitialized: null's behind, but it removes the /my_region node when maxNodes is reached. When I put the LRUPolicy back, I noticed that the region node itself actually gets evicted and gets the unitialized tag, but the 100 most recently used children still remain.

How can I prevent the region itself from being evicted? Is there some better way to do the removal instead of eviction without separating the eviction from expiration?

I'm using jboss-cache version 1.3.0.SP4.

+2  A: 

Did you look in the JBoss-Cache bugs repository?


Edit:

Take a look at this JBoss-Cache bug, it seems quite relevant:

https://jira.jboss.org/jira/browse/JBCACHE-921

Fixed in 1.4.1.SP1

Ehrann Mehdan
That indeed looks relevant, thank you for the research!I'll let you know when I've tried the upgrade whether it indeed solved the problem.
hvrauhal
I updated to 1.4.1.SP3 (as that was easily available in their maven repository) and that indeed fixes the problem! So it was that bug that caused the memory leak.So far it looks like 1.4.1.SP3 was a drop-in replacement for 1.3.1.SP4.Thank you for the research, this made my day! Next time I'll remember to upgrade libraries first when it's easy to see if the problems go away.
hvrauhal