Is there a problem with the AWS ELB Sticky session? Don't forget the Awselb cookie

Source: Internet
Author: User
Tags setcookie elastic load balancer

Our product has two module, deployed on separate Linux machine, module 1 need to launch HTTP request to Module 2 to obtain service. Since Module 2 has multiple units, we will deploy a load balancer (elb,elastic load Balancer) before Module 2. We're deployed in AWS, so we're using AWS ELB.

  

  AWS Elb also provides another good feature, called the Sticky Session, which is to help you direct requests to one of the machines instead of randomly dispersing them to other machines by Elb algorithm. The advantage of this feature is that if my latter request is dependent on the processing of the previous request, the series of requests will be sent to the same machine during this time period.

AWS Elb implements this feature and relies on cookies, which require you to provide a name for a cookie when configured. As a matter of principle, ELB will send requests of the same value to the same machine based on the value of this cookie in the request.

But we tested and found that this was not the case. Sticky session did not work .

  

After troubleshooting, we finally found that the root cause is: when our HTTP request is sent to Module2, response returns, our program will add a cookie to the response header, through the Setcookie, This cookie is a cookie that we configured in ELB for the sticky session. But at the same time Elb will add another cookie to our response header named Awselb, which we did not deal with.

But in fact, on the next request, our Module 1, in addition to having its own cookie, should also have an AWS Elb Cookie, so that the Elb stricky session function will work. The request will be directed to a specific Module 2 machine.

  

  Why didn't we find it before?

1. First we did not setcookie in the response header, so Elb will not help us set Awselb cookies.

2. Elb more traffic load balancing for browser and server.

Awselb's cookie,path=/, that is, all subsequent requests should take this cookie. Browser naturally understands the truth and can handle it correctly. But for our usage scenario, the two module, which uses a network library for HTTP communication, does not have a client such as browser to handle cookies. So we need to deal with it ourselves.

As a result,AWS ELB Usage scenarios are more prepared for communication between browsers and servers .

  

Finally found the cause of the problem, hope to help you.

Still should think more.

  Reference Documentation:

1. http://docs.amazonaws.cn/en_us/ElasticLoadBalancing/latest/DeveloperGuide/US_StickySessions.html

2. http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-sticky-sessions.html# Enable-sticky-sessions-application

  

Kevin Song

June 18, 2015

Is there a problem with the AWS ELB Sticky session? Don't forget the Awselb cookie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.