粘性会话和会话复制 [英] Sticky Sessions and Session Replication

查看:60
本文介绍了粘性会话和会话复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估在 tomcat 中使用带有会话复制的粘性会话的情况.从我的初步评估,我认为如果我们启用会话复制,那么在一个 tomcat 节点启动的会话将被复制到所有其他 tomcat 节点,因此我们不需要粘性会话来继续会话,任何节点都可以接收请求.

I am evaluating the case of using sticky sessions with Session replication in tomcat. From my initial evaluation, I thought that if we enable Session replication, then session started in one tomcat node will be copied to all other tomcat nodes and thus we do not need sticky session to continue sessions and the request can be picked up by any node.

但似乎会话复制通常用于粘性会话,否则每当请求转到其他节点时都需要更改会话 ID.参考:http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html#Bind_session_after_crash_to_failover_node

But it seems that session replication is in general used with sticky sessions, otherwise the session id needs to be changed whenever the request goes to some other node. ref: http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html#Bind_session_after_crash_to_failover_node

如果您必须启用粘性会话,谁能解释一下会话复制的真正用途是什么?因为那样你会不必要地在每个节点上复制会话,当具有给定会话 id 的请求总是去同一个节点时.在节点崩溃的情况下这可能是有益的,但这种情况不会经常发生,并且仅为此使用会话复制似乎是一种矫枉过正.

Can anyone explain what is the real use of session replication if you have to enable sticky session? Because then you would be unnecessarily copying the session on each node, when the request with a given session id is always going to the same node. It could be beneficial in case of a node crashing, but then that does not happen frequently and using session replication only for that seems like an overkill.

推荐答案

我认为唯一真正的好处是能够不假思索地关闭 Tomcat 实例.这尤其适用于今天的云世界(想想 Amazon AWS Spot 实例),因为节点可以经常打开和关闭.对此的替代方法是购买一个支持节点排空的体面的负载均衡器.但是体面的负载平衡器很昂贵,而且耗尽需要时间.

I think the only real benefit is to be able to shut down Tomcat instances without much thinking. Especially this applies today in cloud world (think Amazon AWS spot instances) when nodes can go on and off really often. Alternative to this would be to buy a decent load balancer which supports node draining. But decent load balancers are expensive, and draining takes time.

我能想到的另一种情况是购物车(实施不佳),其中商品保存在 HttpSession 中,关闭将要求用户重新购买它们(这可能会导致销售损失).

Another scenario I can think of is a (poor implementation of) shopping cart where items are kept in the HttpSession and shutting down would require the user to re-purchase them (which would likely lead to a lost sale).

但在大多数情况下,您是对的 - 同时拥有粘性会话和会话复制的好处非常微不足道.

But in most cases you're right - benefit of having both sticky sessions and session replication is very negligible.

这篇关于粘性会话和会话复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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