Về thay đổi ELB idle timeout
Câu hỏi:
Nếu kéo dài ELB idle timeout thì có vấn đề gì không?
Trả lời:
Trước tiên bạn hãy hiểu rằng, với mỗi request đi qua ELB, ELB sẽ giữ 2 connnections:
・ Front-end connection là kết nối giữa client và ELB.
・ Back-end connection là connection giữa ELB và target như là webserver. Thông thường, khi client hoặc server hoàn tất việc gửi/nhận dữ liệu, connection sẽ close dù chưa hết idle timeout. Nếu không có dữ liệu nào được gửi hoặc nhận vào thời điểm mà idle timeout trôi qua, ELB sẽ đóng connection.
Việc tăng idle timeout là cần thiết đối với những hoạt động cần nhiều thời gian như file uploads, tuy nhiên bạn hãy lưu ý điểm sau:
・ “if the application closes the TCP connection to the ELB ungracefully, the ELB might send a request to the application before it receives the packet indicating that the connection is closed. If this is the case, the server refuses the request from the ELB and then the ELB sends an HTTP 502 Bad Gateway error to the application.” [1]
Do đó, bạn nên configure idle timeout của app dài hơn idle timeout configure cho ELB. Với các backend connection, bạn nên enable HTTP keep-alive ở thiết định ở webserver. Nếu enable HTTP keep-alive, ELB có thể sử dụng lại các backend connections đến khi keep-alive timeout hết hạn.
Bạn có thể tham khảo thêm về HTTP keep-alive và thiết định sample cho Apache webserver tại tài liệu [2].
Trường hợp bạn sử dụng webserver engine là Nginx, thì mặc định Keep Alive header được enable. Xem thêm tài liệu [3] để biết thêm thông tin chi tiết.
Tài liệu tham khảo:
[1][Application Load Balancer | Connection idle timeout]
docs.aws.amazon.com/elasticloadbalancing/la..
[2] [ELBのタイムアウトを回避するためApacheのKeepAliveTimeoutを設定する]
dev.classmethod.jp/articles/set_keepaliveti..
[3] How to Enable Keep Alive in NGINX