2.0 Introduction
While HTTP may be a stateless protocol, if the context it’s to convey
were stateless, the internet would be a much less interesting place.
Many modern web architectures employ stateless application tiers,
storing state in shared memory or databases. However, this is not
the reality for all. Session state is immensely valuable and vast in
interactive applications. This state may be stored locally for a num‐
ber of reasons; for example, in applications where the data being
worked is so large that network overhead is too expensive in perfor‐
mance. When state is stored locally to an application server, it is
extremely important to the user experience that the subsequent
requests continue to be delivered to the same server. Another por‐
tion of the problem is that servers should not be released until the
session has finished. Working with stateful applications at scale
requires an intelligent load balancer. NGINX Plus offers multiple
ways to solve this problem by tracking cookies or routing.
NGINX Plus’s sticky directive alleviates difficulties of server affin‐
ity at the traffic controller, allowing the application to focus on its
core. NGINX tracks session persistence in three ways: by creating
and tracking its own cookie, detecting when applications prescribe
cookies, or routing based on runtime variables.
2.0 简介
尽管 HTTP 协议是无状态的协议,但如果互联网访问都是基于无状态的访问的话,
这个世界将会索然无味。但现代的 Web 架构大多基于一个无状态的应用架构,而
将会话(session)存储到内存或数据库中。可惜,这并非全部的事实。会话对于
应用的交互来说功能显著,作用明显。在设计是可能出于一系列的因素考虑,将会
话存储到应用服务器中;其中之一就是需要存储的会话数据太多,导致网络开销太大,
将会话存储在本地服务器,能显著提升能将用户请求分发到同一台服务器的用户体
验;另个方面的考虑是,如果会话没有被销毁,服务器则不应被释放掉。在具有高负
载的应用服务器上使用会话,需要更加智能的负载均衡解决方案。