How to Configure stickiness and autoscaling in elasticbeanstalk application.

0

Hello,

We have a application running on elasticbeanstalk that listens for client request and returns a stream segment. We have some requirements for application:

  1. Client session should be sticky (all request for some session should go to same EC2) for specified time without any changes on client side. (we can't add cookie sending via client). As per my understanding application load balancer supports that and i enabled stickiness in load balancer. As per my understanding load balancer generated cookie are managed by load balancer and we do not need to send cookie through client side.

  2. Based on CPU utilisation we need to auto scale instances, (when CPU load > 80%) we need to scale instances +1.

Problem:-

  1. When i request from multiple clients from same IP address. CPU load goes above 80% and new instance is launched. But after sometime i see CPU load going down . does this mean that 1 of these client are now connected to new instance and load is shared. That means stickiness is not working. Though It is not clear how to test it properly. However sometimes when i tried to stop new instance manually . No client has got any errors. When I stop first instance all client gets 404 error for sometime. How to check whether stickiness is working properly ?

  2. If i get stickiness to work. As per my understanding Load will not be shared by new instance. So Average CPU usage will be same. So autoscaling will keep on launching new instance until max limit. How do i set stickiness with autoscaling feature.

I set stickiness seconds to 86400 sec (24 hours) for safe side.

Can someone please guide me how to configure stickiness and autoscaling proper way ?

3 Answers
1

Hi.

Did you enable sticky sessions on your target group? Is the cookie for sticky session set in the response from ALB with Set-Cookie?

As per my understanding load balancer generated cookie are managed by load balancer and we do not need to send cookie through client side.

Application Load Balancer is cookie-based and sticky. Your client will need to resend the set cookie from the server.
(Network Load Balancer provides sticky based on client IP address so you don't have to resend the cookie.)

profile picture
EXPERT
iwasa
answered 2 years ago
0

iwasa answered your first question already. For the 2nd question:

But after sometime i see CPU load going down

After the new instance is InService in the ASG (AutoScaling Group) its Warmup timer will start (configured on the scaling policy). Once the warmup ends, the new instance will be counted towards the average group metrics. This mean if the first instance was still at 80% load, and the new instance is at 40% load, the average CPU metric will show up as 60%


How to tell if stickyness is working?

You can enabled access logs if this is an ALB and see where requests are landing; otherwise look at your application logs in the instance. But in general, if you have 5 clients on an instance, each with a sticky session; then those 5 will still all be on the first instance after the scale out (because of the sticky session). This is a big reason why you want to try and make applications stateless whenever possible and store session data off instance somewhere like EFS, RDS, etc.


Load will not be shared by new instance. So Average CPU usage will be same. So autoscaling will keep on launching

This isn't correct. The average CPU would go down with the new instance and launching would stop. For an extreme example, assume the first instance is at 80% and the new instance launched after that gets 0 load. Average would be (80 + 0)/2 = 40%, so scaling would stop

AWS
answered 2 years ago
0

Hello @iwasa and @Shahad_C,

Thanks for the reply.

As per the suggestion, I checked in cookie received in response from ALB, It was having a cookie with name AWSALB and 7 days expiry period. As our scenario is we can't send cookie in request from client. I created a new environment with NLB with stickiness.

with NLB, no cookie is received and when CPU loading is above threshold new instance is launched. and CPU load is 0% on new instance. and keeps same on old instance. Average definitely came down of threshold as pointed out by @Shahad_C. Thanks for correcting. No new instance are launched after metrics goes down threshold. So stickiness is working with NLB.

However I checked earlier for ALB uses Round Robin by default. With stickiness probably that is not a good idea. for Network load balancer i want to use Least connection strategy. But NLB does not have any option to edit "Load balancing algorithm" in Attributes. which algorithm NLB uses for balancing by default, can't we edit this ?

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions