[infinispan-dev] Cache Entry is Loaded two times from CacheLoader

Manik Surtani manik at jboss.org
Mon Jan 18 13:26:46 EST 2010


This is an optimisation (believe it or not) in the CacheLoaderInterceptor [1].  Let me explain.  CLI contains a method, loadIfNeeded() (line 113).  Here is the interesting bit:

         if (!loader.containsKey(key)) {
            if (log.isTraceEnabled()) log.trace("No need to load.  Key doesn't exist in the loader.");
            return false;
         }

	....

         loadEntry(ctx, key, n);

So, the optimisation is to actually check that the entry exists in the store prior to calling load, as this often saves on unmarshalling the value, etc, especially if the entry has expired (since loader.containsKey() on an expired value will return false).

Now the problem you see lies in the AbstractCacheLoader[2] where the *default* impl of containsKey() does ... loadEntry() !  So yes, this is crappy and implementations should be much smarter about this.  E.g., a JDBC cache store could be much more efficient in a query for containsKey() than a heavy-handed load.  Similarly, this applies to all other CacheStore impls.

So, yes I agree that the CacheStore *implementations* are inefficient in this regard.  I have created ISPN-337 [3] for this, thanks for reporting.

Cheers
Manik


[1] http://fisheye.jboss.org/browse/Infinispan/trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java?r=1020
[2] http://fisheye.jboss.org/browse/Infinispan/trunk/core/src/main/java/org/infinispan/loaders/AbstractCacheLoader.java?r=209
[3] https://jira.jboss.org/jira/browse/ISPN-337



On 18 Jan 2010, at 17:48, Galder Zamarreno wrote:

> Hi Amin,
> 
> Do you mean when the key is actually expired? Or when the key is loaded again after expiration?
> 
> Cheers,
> Galder
> 
> ----- Original Message -----
> From: "Amin Abbaspour" <a.abbaspour at gmail.com>
> To: infinispan-dev at lists.jboss.org
> Sent: Saturday, January 16, 2010 2:51:32 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
> Subject: [infinispan-dev] Cache Entry is Loaded two times from CacheLoader
> 
> Hi All,
> 
> I put some log in my CacheLoader and noticed that when some key
> expires, the load(key) method (in the case of LockSupportCacheStore
> loadLockSafe method) in CacheLoader is called two times
> consequentially for the same key.
> 
> Of course this creates no logical issues but is not much welcomed from
> performance point of view.
> 
> Regards,
> Amin
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev

--
Manik Surtani
manik at jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org








More information about the infinispan-dev mailing list