Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate second level cache is slow

I am using hibernate second-level caching with in-memory ehcache, and it is slow. I mean, not slower than SQL, but not really faster either given a fast database on an SSD. The actual speed increase is less than a factor of 2, and sometimes unnoticeable.

It seems that others had the same problem, but got no answer: http://forum.spring.io/forum/spring-projects/data/44353-hibernate-second-level-caching-slow-no-really-slow https://forum.hibernate.org/viewtopic.php?t=985913

After some profiling, it seems that hibernate always de/re-hydrates the cache elements, instead of directly storing them, which leads to this abysmal performance (over a factor of 100 compared to direct use of ehcache).

So, my questions are:

  • Can hibernate store and restore the cached objects directly?
  • Is there some other way to speed up the second level cache?
  • Is there a relatively simple alternative mechanism for faster hibernate caching?
like image 577
P.Péter Avatar asked Oct 19 '22 16:10

P.Péter


1 Answers

Can hibernate store and restore the cached objects directly?

No, it can't, because that would mean that concurrent sessions would use the same object instances, thus stepping on each other toes.

Is there some other way to speed up the second level cache?

There are probably thousands of ways to speed it up. Most of them depend on the specific requirements of your application.

Is there a relatively simple alternative mechanism for faster hibernate caching?

No, at least not for the time being.

like image 188
Dragan Bozanovic Avatar answered Oct 21 '22 07:10

Dragan Bozanovic