+86 135 410 16684Mon. - Fri. 10:00-22:00

AWS ELB (Elastic Load Balance)

AWS ELB (Elastic Load Balance)

AWS ELB (Elastic Load Balance)

建立 ELB 要注意的功能

  • Subnet 一定要指定在 Public Subnet, 不然外面會打不進去.
  • 可以跨 AZ, 也建議要有跨 AZ. 但是無法跨 Region.
  • 有 internet-facing 和 internal 兩種.
  • 可以開啟 Access Log, Debug 用途
  • ELB 支援 IPv4 and IPv6 (see FAQ)

Cross-zone Load Balancing

官方文件 開始的描述如下:

By default, your load balancer distributes incoming requests evenly across its enabled Availability Zones. To ensure that your load balancer distributes incoming requests evenly across all back-end instances, regardless of the Availability Zone that they are in, enable cross-zone load balancing.

我翻譯成這樣:

LB 預設值會平均的、且跨越 AZ 來處理 Request。如果打算確保 LB 平均的分散 Request 到所有的 Backend instances,不管那些 instances 是在哪一個 AZ,那麼打開 *Cross-zone Load Balancing*

邏輯上理解 Cross-Zone Enabled/Disabled 的差異:

  • Enabled:平均流量的單位是 instance (不管機器在哪個 AZ)
  • Disabled:平均流量的單位是 AZ (不管 AZ 裡有多少機器)

Best Practice and 官方建議:

  • Enable Cross-Zone Load Balancing
  • 保持兩邊的機器數一樣

另外,ELB 的 CloudWatch – Health count,如果 Cross-Zone 是 Disabled,health count 數值只有實際的一半,Enabled 才是 Instance Count。

官方文件 (Elastic Load Balancing Metrics) 說明如下:

1
The number of healthy instances in each Availability Zone. An instance is considered healthy if it meets the healthy threshold configured for the health checks. If cross-zone load balancing is enabled, the number of healthy instances is calculated across all Availability Zones.

大概意思:每個 AZ 的 healthy instances 數。如果 cross-zone enabled,就會計算所有 AZ 裡的 instance 數

Connection Draining

Drain 翻譯是 “排水” 的意思。如果 ELB 開啟 Connection Draining,那麼以下狀況就會停止送 Request 到 instance:

  • 當 instance 剛剛被 de-register 的時候,正在處理中 (in progress) 的 request 都完成了
  • instance 變成 unhealthy 狀態, 沒有新的 request 進來. 但是持續中的 request 會繼續完成, 也就是可能會出現 HTTP 4XX or 5XX.

使用情境:

  • 通常用在部屬的時候,需要暫時把線上的 instance 移除,但可能還有連線存在。通常線上的服務都會打開,建議可以開 180s 左右。
  • 用在 auto scale 的時候,也需要此功能,正在處理中的 Request 能夠陸續完成。

ELB 可否 Cross Region?

不行,但可以透過 Route53 Routing Policy 指定不同的 region 的 ELB, policy 有 Geolocation, Weight, Latency, … 等方式。

Sticky Sessions

同一個 Session 固定使用同一個 instance。通常是 stateful 的設計,或者後端資源無法 share 的狀況。

一些要注意的 FAQ

以下是整理自 FAQ.

  • 一個 ELB 可以同時處理多個 Port, 像是 80/443, 同時可以 port mapping 不同 instance 的 port. 像是 443 (ELB) to 80 (EC2).
  • ELB 沒有限制連線的上限.

補充一點,如果有瞬間大量的需求,而且時間是可以預期的,那麼可以開 AWS Support ,請 ELB Team 幫忙 Pre-warming ELB. 最好一週前準備。

Reference