Is 2 level cache in use?

#1

Hi,

Is there any way to check, if 2 level cache is in use? Right now I've done two things:

1. objectdb.conf with cache size is placed in WEB-INF directory of my web application.

2. persistence.xml was modified with:

    <properties>
      <property name="javax.persistence.sharedCache.mode" value="ALL"/>
    </properties>

But after few benchmarks I don't really see any difference in performance. ODB on server uses the same amount of CPU and memory. I'm calling the same url in benchmark, so most of the data should be in cache. ODB and Tomcat are on different servers.

#2

You cannot check if the L2 cache is enabled directly but you can check its content, by using emf.getCache().contains(entityClass, primaryKey), so you can persist or retrieve an entity object and then check if it is cached.

The L2 cache doesn't always improve performance. It depends on the application. Sometimes enabling the L2 cache may slow the application because of the overhead in keeping it up to date and the memory that it consumes. Therefore, it is disabled in the default configuration by setting its size to 0.

The main problem with the default implementation is that the server doesn't know what is cached on the client side, and therefore when a query is executed by the server it prepares all the results, regardless the cache. So the cache is mainly useful for retrieval by find and by navigation (and not in queries).

You may try the following undocumented ObjectDB query hint and check if it helps:

 query.setHint("objectdb.result-fetch", "lazy");

This is an instruction to the ObjectDB server to return references rather than entity objects as results, which can help in using the L2 cache on the client side. It might be mainly useful in queries that can be resolved by indexes without accessing the primary data.

Currently this hint must be set at the query level (as demonstrated above) - but it should be supported in all other query hint scopes in future versions.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thanks for the explanation. I will do some more tests on this.

#4

Basic documentation regarding this feature was added to the Query Hints section.

It is now supported in all scopes (e.g. also globally as a persistence unit property).

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login