[ELB] Connection Draining

2021. 7. 28. 10:01DevOps/AWS

 

Usecase

한 기술 회사에서 운영하는 서비스는 ELB(Elastic Load Balancer)뒤에 EC2 인스턴스를 두고 부하를 분산하는 방식을 사용하고 있습니다. 이때, EC2가 health check에 실패하여 unhealthy상태로 들어가게 되면 진행중이던 in-flight Request가 끊어지는 이슈가 발생하게 됩니다. 이를테면, 특정 EC2 인스턴스로부터 수십초가 걸리는 파일 다운로드를 수행중이라고 했을 때, 파일을 다운로드받는 도중, 해당 인스턴스가 unhealthy상태로 바뀌게 되면 커넥션이 끊어지면서 파일 다운로드에 실패하게 되는 것입니다. 이러한 상황을 막기 위해 취할 수 있는 방법에는 어떤 것이 있습니까?

 

Connection Draining

When Connection Draining is enabled and configured, the process of deregistering an instance from an Elastic Load Balancer gains an additional step. For the duration of the configured timeout, the load balancer will allow existing, in-flight requests made to an instance to complete, but it will not send any new requests to the instance. During this time, the API will report the status of the instance as InService, along with a message stating that “Instance deregistration currently in progress.” Once the timeout is reached, any remaining connections will be forcibly closed. - AWS

 

Connection Draining은 특정 인스턴스가 unhealthy상태로 바뀌었더라도, 해당 시점에 인스턴스가 처리하고 있는 in-flight request가 있다면, 해당 Request가 처리될 때까지 커넥션을 유지합니다. 해당 Connection을 유지하는 최대 시간(maximum timeout)을 명시적으로 설정할 수 있으며, maximum timeout을 초과할 경우에는 인스턴스가 해당 커넥션을 강제 종료합니다.

 

 

Connection Draining을 사용하면 위와 같은 상황(파일을 다운로드 하는 도중 인스턴스가 unhealthy로 바뀌는 상황)에서도 maximum timout까지 커넥션을 유지하기 때문에 파일을 계속 다운로드 받을 수 있습니다. (물론 타임아웃 시간보다 다운로드 잔여 시간이 길면 완료되지 않을 수 있습니다.)

 

 

 

 

Target Groups

When you deregister a target, the load balancer waits until in-flight requests have completed. This is known as 
connection draining. The status of a target is draining while connection draining is in progress. - AWS

 

또 다른 방법은 Load Balancer뒤에 EC2 인스턴스를 바로 연결하는 것이 아니라, Target Group을 생성하고, 해당 Target Group으로 포워딩 하는 것입니다. Target Group을 사용하면 오토 스케일링을 구성하는데 비교적 용이하며, 기본적으로 Connection Draining을 지원하므로 별도의 설정이 필요 없다는 장점이 있습니다. 

 

 

 

Reference

https://aws.amazon.com/ko/blogs/aws/elb-connection-draining-remove-instances-from-service-with-care/

 

ELB Connection Draining – Remove Instances From Service With Care | Amazon Web Services

AWS Elastic Load Balancing distributes incoming traffic across multiple Amazon EC2 instances: You can use Elastic Load Balancing on its own, or in conjunction with Auto Scaling. When combined, the two features allow you to create a system that automaticall

aws.amazon.com

https://docs.amazonaws.cn/en_us/elasticloadbalancing/latest/application/target-group-register-targets.html

 

Register targets with your target group - Elastic Load Balancing

Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China. Register targets with your target group You registe

docs.amazonaws.cn

 

반응형