简体   繁体   English

每个节点的基于微服务的架构和单独的缓存

[英]Microservices based architecture and individual cache for each node

Is it considered bad practice to use separated, local cache for each node in distributed microservice application?在分布式微服务应用程序中为每个节点使用单独的本地缓存是否被认为是不好的做法? I've heard that in monolithic application it's OK to use local EHCache as 2nd level cache provider for Hibernate, but in distributed environment it's common practice to use distributed caches, such as Memcached, Redis or Hazelcast.我听说在单体应用程序中,可以使用本地 EHCache 作为 Hibernate 的二级缓存提供者,但在分布式环境中,通常的做法是使用分布式缓存,例如 Memcached、Redis 或 Hazelcast。 What are the consequences of using separated cache for each node?为每个节点使用单独的缓存有什么后果?

"There are only two hard problems in Computer Science:cache invalidation and naming things."-- Phil Karlton “计算机科学中只有两个难题:缓存失效和命名事物。”-- Phil Karlton

The main problem with local cache in app-server is that it makes cache invalidation much more hard that it was before. app-server 中本地缓存的主要问题是它使缓存失效比以前更加困难。

Each time a resource change, it has to be invalidated (and updated) on all the local caches.每次资源更改时,它都必须在所有本地缓存​​上失效(和更新)。 This would require a system that knows about all the cache servers running at any point of time.这将需要一个了解在任何时间点运行的所有缓存服务器的系统。 This system would have to be informed about all updates so that it can co-ordinate the data invalidation on all servers.该系统必须被告知所有更新,以便它可以协调所有服务器上的数据失效。 It will also have to take care of retries, handling failed servers, etc.它还必须处理重试、处理失败的服务器等。

If your application server has it's own local cache, you will have to solve these problems yourselves using a separate system or in the application code.如果您的应用服务器有自己的本地缓存,您将不得不使用单独的系统或在应用程序代码中自己解决这些问题。 A distributed caching system, would have solved those problems for you.分布式缓存系统可以为您解决这些问题。 You can make an update call and on success have a guarantee of data consistency (or eventual consistency).您可以进行更新调用,并在成功后保证数据一致性(或最终一致性)。

It is separation of concerns.它是关注点分离。 With a separate cache cluster, the caching logic and the associated problems are handled at one place.使用单独的缓存集群,缓存逻辑和相关问题在一个地方处理。 The same cluster can be reused for multiple applications easily, rather than redoing the same for each application you develop.同一个集群可以轻松地重用于多个应用程序,而不是为您开发的每个应用程序重做相同的工作。

Another minor disadvantage is that you would have to warm up the cache each time you spawn a new server, if you don't want a performance degradation.另一个小缺点是,如果您不希望性能下降,则每次生成新服务器时都必须预热缓存。 This would lead to longer time to spawn servers.这将导致生成服务器的时间更长。

Here we can do one more thing is to use message broker for cache invalidation.这里我们可以做的另一件事是使用消息代理进行缓存失效。

Use kafka or any other queue to catch packets and invalidate them.使用 kafka 或任何其他队列来捕获数据包并使它们无效。

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

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