3 Replies Latest reply on Aug 1, 2007 7:47 PM by starksm64

    TimedCachedPolicy never removes entries from cache

    frebe73

      I have been performance testing JBoss (3.0.2) by making many client calls from houndreds of different users. I noticed that the Authentication cache (JaasSecurityManager$DomainInfo objects) just increased. Old users were never removed from the cache. When I checked the source for TimedCachePolicy (which have the cache functionality) I read in the comments that TimedCachePolicy is a lazy cache. Entries can only be removed when asked for. The only way to remove entries from the cache is to manually flush the cache.

      I can't belive it is supposed to be this way. Someone must have used JBoss for applications with thousands of users and encountered OutOfMemory-exception because of this. Is is anyone that have a idea about how to solve this??

      /Fredrik

        • 1. Re: TimedCachedPolicy never removes entries from cache

          Still have exactly the same issue in jboss4.0.4GA (probably JBOSS4.0.5.GA as sources of this part are not changed).
          We also have thousands of users.
          For a moment only possible solution is to extend TimedCachePolicy class and reiplement run() method. Currently this method only changes current time.
          But expired objects can be removed at this time.

          public void run() {
          super.run();
          synchronized (entryMap) {
          Iterator iter = entryMap.entrySet().iterator();
          List removeentries = new ArrayList();
          while (iter.hasNext()) {
          Map.Entry entry = (Map.Entry) iter.next();
          TimedEntry value = (TimedEntry) entry.getValue();

          if (value.isCurrent(now) == false) {
          if(log.isDebugEnabled()){
          log.debug("destroying object:"+value);
          }

          value.destroy();
          removeentries.add(entry.getKey());
          }

          }
          for (Object object : removeentries) {
          if(log.isDebugEnabled()){
          log.debug("removing object from Map:"+object);
          }

          entryMap.remove(object);
          }
          }

          }

          • 2. Re: TimedCachedPolicy never removes entries from cache
            anil.saldhana

            This discussion is wrt
            http://jira.jboss.com/jira/browse/JBAS-3986

            I am wondering maybe we can flush the cache at a configurable number of access. If the cache is accessed at say the 100th time, do a cache flush.

            • 3. Re: TimedCachedPolicy never removes entries from cache
              starksm64

              Sure, but the impl needs to be updated to use a ConcurrentHashMap so that the flush is not blocking access. You could also look at using the java.util.concurrent.DelayQueue to know exactly when entries have expired and how many have expired.