Glassfish Amazon AWS EC2 实例和 ELB 缓存问题
我有 2 个运行 Glassfish 应用程序服务器的 EC2 实例(运行完全相同的已部署应用程序),并且这些实例在弹性负载均衡器下运行。这很有效,但我担心缓存与 EJB 不一致。
情况: 客户端向 ELB 发送请求,ELB 转发到 EC2 实例 1。某些 EJB 对象(我们称之为 EJB1)被缓存。 客户--> ELB--> EC2-1(EJB1 已缓存)
不久之后,客户端发送另一个请求,但该请求现在被转发到 EC2 实例 2。EJB1 现在已缓存在该实例上。 客户--> ELB--> EC2-2(EJB1 已缓存)
不久之后,客户端发送另一个请求并转发到 EC2 实例 1。EJB1 仍在缓存中,但不是最新的,从而导致缓存不一致。 客户--> ELB--> EC2-1(EJB1 缓存)
不幸的是,我还没有真正看到这个问题,但我觉得这是有可能的。除了关闭 EJB 缓存之外,防止这种情况发生的正确方法是什么?
谢谢。
I have 2 EC2 instances running Glassfish app server (running the exact same deployed application) and these run under an Elastic Load Balancer. This is working great but I am worried about caching inconsistencies with the EJBs.
Situation:
Client sends request to ELB which forwards to EC2 instance 1. Some EJB object, let's call it EJB1, gets cached.
Client --> ELB --> EC2-1 (EJB1 cached)
A short time later Client sends another request but this gets forwarded now to EC2 instance 2. EJB1 now is cached on that instance.
Client --> ELB --> EC2-2 (EJB1 cached)
A short time later Client sends another request and is forwarded to EC2 instance 1. EJB1 is still in cache but is not up to date, thus causing a cache inconsistency.
Client --> ELB --> EC2-1 (EJB1 cached)
Unfortunately I haven't been able to actually see this issue yet but I feel that it's a possibility. Other than turning caching of EJBs off, what is the proper way to prevent this from happening?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Amazon 提供“会话粘性”。这意味着,假设用户启用了 cookie,它们在会话的生命周期内将被发送到同一个 EC2 实例。
Amazon provides "session stickiness" support at the load balancer. This means, assuming the user has cookies enabled, they are sent to the same EC2 instance for the lifetime of their session.
在实现 2 级缓存之前,您的实例不会共享缓存。
以下是 2 级缓存解决方案的几个链接。
(开源)http://www.terracotta.org/ehcache/
(大量现金) http://www.oracle.com/technetwork/中间件/coherence/overview/index.html
Until you implement a level 2 cache your instances are not going to share the cache.
Here are a couple of links for level 2 caching solutions.
(open source) http://www.terracotta.org/ehcache/
(lots of cash) http://www.oracle.com/technetwork/middleware/coherence/overview/index.html