user191776
user191776

Reputation:

Hibernate Caching Causes Performance Drop on Low Percentage of @Cacheable Entities?

I have a Java application that uses the Hibernate persistance library, with about 100 mapped classes. To try out second-level caching, I added @Cacheable to 5 of the mapped classes. This caused a standard computation task to take double the time it used to take earlier, although there were several hits on the cached items (as evidenced on the Couchbase cache monitoring console). I can't get the exact average hit ratio due to the transient nature of Couchbase stats, but I estimate it at just about 10-20%.

Does enabling caching for some entities affect the access times for other entities not marked as @Cacheable, causing this performance drop? Or is it caused merely by the added latency of cache querying coupled with a low hit ratio on the cached items?

I'm using Hibernate 3.3. I've disable query caching. I got similar results with Memcached & GemFire as the cache providers.

Upvotes: 2

Views: 419

Answers (1)

Galder Zamarreño
Galder Zamarreño

Reputation: 5197

Well, I guess it depends on what the cache provider does to see if the entry is cached. If this is an expensive operation, retrieving data from the database will be expensive if the cache hit ratio is low. In general, cache providers should strive to make this as cheap as possible. For example, in the case of Infinispan, this is a simple in-memory check to see if the entity is cached or not, and if not, the entry is retrieved from the database via Hibernate and Infinispan cache provider puts it in the cache using a very efficient put operation called putForExternalRead.

You should really give Infinispan cache provider a go. More info in https://docs.jboss.org/author/x/FgY5. If you're running within JBoss AS7, please read https://docs.jboss.org/author/x/LoJ7 instead.

Disclaimer: I'm an Infinispan developer.

Upvotes: 1

Related Questions