`

Sticky Sessions vs Non-Sticky Sessions

 
阅读更多

Non-Sticky Session

Amazon EC2’s Elastic Load Balancing feature just became a bit more powerful. Up until now each load balancer had the freedom to forward each incoming HTTP or TCP request to any of the EC2 instances under its purview. This resulted in a reasonably even load on each instance, but it also meant that each instance would have to retrieve, manipulate, and store session data for each request without any possible benefit from locality of reference.

Suppose two separate web browsers each request three separate web pages in turn. Each request can go to any of the EC2 instances behind the load balancer, like this:

 

This configuration was the original idea for the manager and its implementation was documented here. Its main features are the following:

  • The non-sticky configuration produces the most fair balancing.
  • All the sessions are managed by all the servers that receives request for that session. But the session is cleared, ie, the attributes of the session are only in the local session while the request lives in the container, once the session is unlocked the attributes are cleared.
  • Error conditions in the repo are immediately detected (session is always read and written, no caching is done).
  • This configuration needs the server to lock/unlock sessions and that operations represents some performance degradation (there are more operations performed and more complex).
  • Locking can produce some weird behaviors if the application sends several requests at the same time or in parallel (usually applications that uses web-services a lot). In normal applications (one request, one page) this effect is meaningless.

When a particular request reaches a given EC2 instance, the instance must retrieve information about the user from state data that must be stored globally. There’s no opportunity for the instance to cache any data since the odds that several requests from the same user / browser will go down as more instances are added to the load balancer.

With the sticky session feature, it is possible to instruct the load balancer to route repeated requests to the same EC2 instance whenever possible. 

 

Sticky Session


 

When a particular request reaches a given EC2 instance, the instance must retrieve information about the user from state data that must be stored globally. There’s no opportunity for the instance to cache any data since the odds that several requests from the same user / browser will go down as more instances are added to the load balancer.

With the new sticky session feature, it is possible to instruct the load balancer to route repeated requests to the same EC2 instance whenever possible.

 

The implementation of the sticky configuration is well commented in this post. Features of this configuration:

  • A sticky configuration is simpler and, therefore, faster. In this kind of configuration the manager can assume it is the only one managing and modifying the session and that saves some access to the external repository.
  • A sticky configuration makes each application server to only store the sessions that are being re-directed to it. In a normal (no failure) situation a server knows nothing about the sessions in the other containers.
  • The sticky configuration saves operations against the repository but it needs to maintain the whole session in memory (because the session is not re-read, the saved attributes should be mantained).
  • Normally a sticky configuration produces a more unfair balancing of the requests (but fair enough in my humble opinion).
  • Cos the session is cached in the local server, an error in the repository could be detected not as fast as in non-sticky situations.

 

There are two main downsides:

  1. Your load isn't evenly distributed. Sticky sessions will stick, hence the name. While initial requests will be distributed evenly, you might end up with a significant number of users spending more time than others. If all of these are initially set to a single server, that server will have much more load. Typically, this isn't really going to have a huge impact, and can be mitigated by having more servers in your cluster.

  2. Proxies conglomerate users into single IP's, all of which would get sent to a single server. While that typically does no harm, again other than increasing individual server loads, proxies can also operate in a cluster. A request into your F5 from such a system would not necessarily be sent back to the same server if the request comes out of a different proxy server in their proxy cluster.

 

下面这篇文章是对ELB Sticky Sessions的讲解:

Elastic Load Balancing with Sticky Sessions 

  • 大小: 21.4 KB
  • 大小: 21.8 KB
分享到:
评论

相关推荐

    socket-starter:socket.io 2 + Express 4 + Node.js集群+ MongoDB Sticky-Session

    最新的[可选]集群Express,带有Socket.IO和[可选] MongoDB Sticky-Session 这是什么? 如果您仅能够生成一个进程,并且希望拥有一个具有static content serving的express应用程序,并且同时生成X个使用node并可以...

    web项目集群时共享session方案实践

    3. ** Sticky Sessions** - 负载均衡器会确保来自同一用户的请求始终被转发到同一台服务器,这样Session就不用共享。 - 优点:简单易实现,无需改动应用代码。 - 缺点:如果服务器故障,用户需要重新登录,且可能...

    Apache+Tomcat负载均衡及Session绑定的实现 for windows

    Sticky Sessions策略让客户端始终与创建Session的特定服务器交互,而Session Replication则是将Session数据复制到集群中的所有服务器。 3. **Apache与Tomcat集成** - **Apache配置**:在Apache服务器的httpd.conf...

    负载均衡 LNMP框架安装需求文件.zip

    7. **nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip**:这是一个Nginx的扩展模块,用于实现负载均衡时的会话持久化(sticky sessions)。这有助于确保来自同一用户的请求被定向到同一台后端服务器,提高...

    ntop中文手册与详细介绍

    - `-c` 或 `--sticky-hosts`: 保持主机信息,即使它们暂时离线也会被保留。 - `-e` 或 `--max-table-rows`: 设置表格的最大行数,用于限制显示的数据量。 - `-f` 或 `--traffic-dump-file`: 将流量数据导出到指定...

    session一致性的解决方案.docx

    4. **Session会话粘连(Sticky Sessions)** - 方法一:四层代理Hash。基于用户IP进行Hash,确保同一IP的请求始终指向同一服务器。 - 方法二:七层代理Hash。利用HTTP协议中的特定业务属性(如SID)进行Hash,更...

    django-sticky-crumbs:Django 的粘性面包屑>=1.6.1 基于 django-breadcrumbs 的实现(由 Felipe 'chronos' Prenholato)

    姜戈粘性面包屑 Django 的粘性面包屑>=1.6.1 基于 django-breadcrumbs 的实现(由 Felipe 'chronos' Prenholato)。... 确保您已将 'django.contrib.sessions' 包含在您的 settings.INSTALLED_APPS 中 确保您

    nginx-upstream-jvm-route nginx共享Session

    7. **其他Session共享策略**:除了上述的Nginx-upstream-jvm-route,还可以使用如 sticky sessions(基于Cookie的粘滞会话),通过在客户端保存特定的服务器标识来实现Session的保持;或者利用外部存储如Redis、...

    tomcat-session-manager环境构建资源

    5. **Nginx配置**:Nginx作为反向代理服务器,需要配置负载均衡策略,比如轮询、最少连接数等,同时还需要配置Session黏滞(Sticky Sessions)以确保Session一致性。 6. **安全性与性能优化**:在集群环境下,需要...

    Tomcat集群Session共享

    3. **Session粘滞( Sticky Sessions)方案** - 实现过程:负载均衡器根据特定策略(如Session ID)将来自同一用户的请求定向到固定的Tomcat节点。 - 优点:实现简单,减少Session同步需求。 - 缺点:单点故障,...

    passenger-nodejs-websocket-demo:Phusion乘客

    Phusion Passenger:Node.js WebSocket演示 此应用程序通过使用了不起的,展示WebSocket支持。... passenger start --sticky-sessions 访问位于的演示应用程序,并查看其运行情况。 长时间的轮询支持需要粘性会

    jboss集群配置方式及使用

    <web-session-manager id="default" sticky-sessions="false" sticky-sessions-strict="false" /> ``` 通过上述步骤,可以完成基本的JBoss AS 5集群配置。当然,实际生产环境中的集群配置可能会更加复杂,需要...

    nginx tomcat集群 session复制

    - **粘滞会话(Sticky Sessions)**:Nginx将用户的请求转发到上次处理该会话的Tomcat实例,以保持Session一致性。 - **共享存储**:使用共享内存或数据库存储Session数据,所有Tomcat实例都可以访问。 - **基于TCP...

    Redis-Session-同步

    这可以是基于Session ID的黏滞会话(Sticky Sessions)策略,也可以通过在请求中附加Session ID来实现。 6. **安全考虑**:Redis作为内存数据库,其数据安全性尤为重要。需要设置适当的Redis访问权限,避免未授权的...

    解决session不同问题所需jar包

    这个jar包可能是实现了Session共享或复制的解决方案,例如使用粘性会话(Sticky Sessions)或者Session复制。 首先,我们来了解一下什么是Session。Session是Web应用中用于跟踪用户状态的一种机制,它在服务器端...

    Apache+Tomcat5.0实现集群

    - Tomcat可以通过 sticky sessions 或者分布式session存储(如Memcached或Redis)来实现session复制。 通过以上步骤,可以成功地在Apache和Tomcat之间建立集群,并实现负载均衡和session复制。这不仅提高了服务的...

    apache+tomcat+mysql 的负载平衡和集群技术

    - **粘滞会话(Sticky Sessions):** - 通过配置 `<Valve className="org.apache.catalina.ha.session.JSessionIdCookieProcessorValve"/>` 实现客户端与特定服务器之间的粘滞会话。 #### 二、MySQL 数据库集群 ...

    reids+tomcat8.5+tengine实现session相关jar包.zip

    在分布式架构中,Tengine可以作为负载均衡器,通过特定的配置实现Session黏滞(Sticky Sessions),确保用户的请求始终被转发到保存其Session的服务器上。 4. **Session共享原理**:通过在Tomcat中集成一个session...

Global site tag (gtag.js) - Google Analytics