简体   繁体   English

使用redis缓存java对象:为什么它应该比ConcurrentHashMap更好?

[英]Using redis to cache java objects: why it should be better than a ConcurrentHashMap?

When profiling a java application currently under development at work, we have detected a few bottle necks that we can get rid of using caching. 在分析当前正在开发的Java应用程序时,我们已经检测到了一些我们可以使用缓存摆脱的瓶颈。 The application process requests and it should be as fast as possible doing so. 应用程序进程请求并且应该尽可能快地执行。 We are considering Redis as cache solution because we already use it in the application. 我们正在考虑将Redis作为缓存解决方案,因为我们已经在应用程序中使用它。 Basically we have to cache java objects. 基本上我们必须缓存java对象。 With Redis we have to serialize / deserialize those objects + network overhead. 使用Redis,我们必须序列化/反序列化这些对象+网络开销。 Given that basically Redis is a key value store, I was wondering if it may be more efficient to use a ConcurrentHashMap instead of Redis, as that will save us the serialization and network overhead. 鉴于基本上Redis是一个键值存储,我想知道使用ConcurrentHashMap而不是Redis是否更有效,因为这将节省我们的序列化和网络开销。 However, searching in the internet, I could not find anyone using it for this purpose. 但是,在互联网上搜索,我找不到任何人为此目的使用它。 Am I missing something? 我错过了什么吗? Which is the practical limit of the ConcurrentHashMap for this purposes (in terms of concurrent requests and cached data volume)? 为此目的,ConcurrentHashMap的实际限制是什么(就并发请求和缓存数据量而言)?

IMHO, ConcurrentHashMap is a suitable cache provided 恕我直言,ConcurrentHashMap是一个合适的缓存提供

  • you don't need external access 你不需要外部访问
  • the total heap size is not too large eg 4 GB 总堆大小不是太大,例如4 GB
  • the level of concurrency is not more than about 20 CPUs (not just threads) 并发级别不超过20个CPU(不仅仅是线程)
  • it has the functionality you need. 它具有您需要的功能。
  • your expiry model is very simple. 你的到期模型很简单。

Redis is designed to do much more than just cache values, and can be shared between processes using different languages, or even accessed via command line. Redis的设计目的不仅仅是缓存值,还可以在使用不同语言的进程之间共享,甚至可以通过命令行访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM