Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I have a cloud of server instances running at Amazon using their load balancer to distribute the traffic. Now I am looking for a good way to gracefully scale the network down, without causing connection errors on the browser's side.

As far as I know, any connections of an instance will be rudely terminated when removed from the load balancer.

I would like to have a way to inform my instance like one minute before it gets shut down or to have the load balancer stop sending traffic to the dying instance, but without terminating existing connections to it.

My app is node.js based running on Ubuntu. I also have some special software running on it, so I prefer not to use the many PAAS offering node.js hosting.

Thanks for any hints.

1 Answer

0 votes
by (44.4k points)

This idea uses the ELB's capability to detect an unhealthy node and remove it from the pool BUT it relies upon the ELB behaving as expected in the assumptions below. This is something I've been meaning to test for myself but haven't had the time yet. I'll update the answer when I do.

Process Overview

The following logic may be wrapped and run at the time the node must be shut down.

  1. Block new HTTP connections to nodeX, however, continue to allow existing connections
  2. Wait for existing connections to empty, either by monitoring existing connections to your application or by allowing a "safe" amount of time.
  3. Initiate shutdown on the nodeX EC2 instance using the EC2 API directly or Abstracted scripts.

"safe" in line with your application, which may not be possible to determine for some applications.

Assumptions that need to be tested

We know that ELB removes unhealthy instances from its pool I'd expect this to be graceful, so that:

  1. A new connection to a recently closed port will be gracefully redirected to a successive node within the pool
  2. When a node is marked Bad, the already established connections to that node are unaffected.

possible test cases:

  • Fire HTTP connections at ELB (E.g. from a curl script) logging the results during scripted opening-closing of one of the nodes HTTP ports. You would have to be compelled to experiment to find an appropriate amount of time that permits ELB to always determine a state change.
  • Maintain a long HTTP session, (E.g. file download) whereas blocking new HTTP connections, the long session should hopefully continue.

1. How to block HTTP Connections

Use a local firewall on nodeX to dam new sessions but continue to enable established sessions.

For example IP tables:

iptables -A INPUT -j DROP -p tcp --syn --destination-port 

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...