使用Redis休眠二级缓存-会提高性能吗? [英] hibernate second level cache with Redis -will it improve performance?

查看:228
本文介绍了使用Redis休眠二级缓存-会提高性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Spring MVC4 hibernate 4 开发应用程序。我已经实现了休眠二级缓存以提高性能。如果我使用 Redis ,它是内存中的数据结构存储,用作数据库,缓存等,性能会提高,但会发生巨大变化吗?

I am currently developing an application using Spring MVC4 and hibernate 4. I have implemented hibernate second level cache for performance improvement. If I use Redis which is an in-memory data structure store, used as a database, cache etc, the performance will increase but will it be a drastic change?

推荐答案

如果您缓存什么是要缓存的东西,并避免缓存根本不应该缓存的数据,则可能会出现巨大差异。情人眼中的美丽就像表演一样。使用休眠AS二级缓存提供程序时,应注意以下几个方面:

Drastic differences you may expect if you cache what is good to be cached and avoid caching data that should not be cached at all. Like beauty is in the eye of the beholder the same is with the performance. Here are several aspects you should have in mind when using hibernate AS second level cache provider:

无自定义序列化-占用大量内存

如果使用二级缓存,则将无法使用快速序列化框架(例如Kryo),并且必须坚持使用可烂的Java可序列化。

No Custom serialization - Memory intensive
If you use second level caching, you would not be able to use fast serialization frameworks such as Kryo and will have to stick to java serializable which sucks.

对于每种实体类型,此方法的顶部都是一个单独的区域,在每个区域内,每个实体的每个键都有一个条目。
就内存效率而言,这是低效的。

On top of this for each entity type you will have a separate region and within each region, you will have an entry for each key of each entity. In terms of memory efficiency, this is inefficient.

缺乏存储和分发丰富对象的能力

大多数现代高速缓存还具有计算网格功能,将您的对象分成许多小块会降低您在保证数据共置的情况下执行分布式任务的能力。这一点取决于Grid提供程序,但是对于许多网格提供程序来说是一个限制。

Lacks the ability to store and distribute rich objects
Most of the modern caches also present computing grid functionality having your objects fragmented into many small pieces decrease your ability to execute distributed tasks with guaranteed data co-location. That depends a little bit on the Grid provider, but for many would be a limitation.

次优性能

取决于您需要多少性能以及使用休眠二级缓存的类型的应用程序是好是坏。就即插即用而言,这是件好事。。。。。。。。。。。。。。。。。。。设计丰富的模型还意味着更多的前期工作和更多的OOP。

Sub optimal performance
Depending on how much performance you need and what type of application you are having using hibernate second level cache might be a good or a bad choice. Good in terms that it is plug and play...." kind of..." bad because you will never squeeze the performance you would have gained. Also designing rich models mean more upfront work and more OOP.

缓存本身的受限查询功能

在缓存提供程序上,但是某些提供程序确实做得不好,而JOIN的Where子句不同于ID。例如,如果您尝试在Hazelcast上为查询建立索引并在内存中建立索引,您将明白我的意思。

Limited querying capabilities ON the Cache itself
That depends on the cache provider, but some of the providers really are not good doing JOINs with Where clause different than the ID. If you try to build and in memory index for a query on Hazelcast, for example, you will see what I mean.

这篇关于使用Redis休眠二级缓存-会提高性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆