简体   繁体   English

如何避免粘性会话?

[英]How to avoid sticky sessions?

I am trying to understand and figure out how can sticky sessions be avoided in general. 我试图了解并弄清楚一般如何避免粘性会话。

I researched to come across a lot about, Sticky and NON-Sticky sessions and Pros and Cons of Sticky Session / Session Affinity load blancing strategy? 我研究了很多有关粘性和非粘性会话以及粘性会话/会话亲和力负载平衡策略的优缺点的信息? And how sticky sessions are to be avoided at all costs but none of these resources and questions really mentioned an alternative strategy to sticky sessions or how else to maintain user state. 以及如何不惜一切代价避免粘性会话,但是这些资源和问题都没有真正提到粘性会话的替代策略或如何维护用户状态。

Some ideas that come to mind are a central DB of sorts to keep track of sessions but that seems to be bad design too. 我想到的一些想法是用于跟踪会话的各种中央数据库,但这似乎也是不好的设计。

You can actually go with a combination of a distributed cache (Redis) and central DB as well. 实际上,您也可以结合使用分布式缓存(Redis)和中央数据库。 Read from Cache and DB eventually for consistency, while write all your cached data into DB at regular intervals. 最终从缓存和数据库中读取数据是为了保持一致性,同时将所有缓存的数据定期写入数据库。

The Cache and DB datastructure should have expiration time as well and you can reset the time everytime an action happens. 缓存和数据库数据结构也应具有到期时间,并且您可以在每次操作发生时重置时间。 This is an approach if you want to avoid Sticky sessions. 如果您要避免粘性会话,这是一种方法。 Sticky Sessions do not fail more often, shows inconsistency if loadbalancing is based on IP Address config. 粘性会话不会更频繁地失败,如果负载均衡基于IP地址配置,则会显示不一致。

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

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