Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Hi,
I have a query about Hibernate 2nd level caching which I wondered whether anyone knows the answer to?
We have a set of data in a couple of tables in an Oracle database that is maintained by an external application. We don't mind if the application's view of this data is slightly out of date. Therefore, we use Hibernate's Query and 2nd level caches with a cache timeout set to a time period we can live with. Currently, the cache we have plugged in happens to be OSCache.
With the above requirements, it seemed logical that the choice of of caching should be cache-usage="read-only".
With this setting the CacheFactory class creates a ReadOnlyCache class. However, under high load this class became a bottleneck as both its get and put methods are fully synchronised leading to lots of blocked threads all trying to use the get method.
A simple "solution" that seems to work is to change the cache-usage to cache-usage="nonstrict-read-write" which means that the CacheFactory creates a NonStrictReadWriteCache class. This class doesn't synchronise the get and put put methods. When testing the app under high load we no longer get blocking in the Hibernate layer.
So I have a couple of questions if anyone is able to help
a) does anyone know why the ReadOnlyCache class synchronises on both the get and the put methods. My (probably too simplistic) thoughts on this is that it should be the job of the plugged in cache (OSCachee) to peform the synchonisation (hopefully at the "slot" level rather than on the whole cache or cache get/put methods)
b) as we changed to the NonstrictReadWriteCache class, does this mean that Hibernate is now having to do any more work compared to if it was told to use ReadOnlyCache. To clarify, I don't mean extra work in the XxxxxCache class itself (as I've read the code for these classes) - I mean does setting nonstrict-read-write cause Hibernate to perform any other work outside the NonstrictReadWriteCache.
As ever, many thanks for any information anyone can provide.
Cheers
Aidan