指標 “超出了進/出站網絡帶寬限額 — Network-xxx-Exceeded” 什麼是?

當客戶端(Redis Client)操作求請量,在特定時間點、存取特定目標端節點時,若是網路用量(In or Out)超過該節點實例效能上限時,此時超量的封包就會等待傳輸(Package Queue)、或是被丟包(Package Drop)。此時客戶端就會出現,操作延遲(Latency)變高、連線超時(Connection timeout)、或是操作失敗的狀況發生。

Jerry’s Notes
What’s next?
13 min readDec 24, 2022

--

“超出其網路限制 — Network-xxx-Exceeded” 的相關指標是下面幾個。

* NetworkBandwidthInAllowanceExceeded
* NetworkBandwidthOutAllowanceExceeded ← — 超出了出站網路帶寬限額。常見的問題。
* NetworkConntrackAllowanceExceeded
* NetworkLinkLocalAllowanceExceeded
* NetworkPacketsPerSecondAllowanceExceeded

首先您要先了解有些 “實例級別” 的指標,是跟網路有關的,請參考以下文檔。

[+] 主機層級指標 — Amazon ElastiCache for Redis:
https://docs.aws.amazon.com/zh_tw/AmazonElastiCache/latest/red-ug/CacheMetrics.HostLevel.html
— -
The AWS/ElastiCache namespace includes the following host-level metrics for individual cache nodes. These metrics are measured and published for each Cache node in 60-second intervals.
— —

!!! 以下說明時間單位為 "每一分鐘"。

NetworkBytesIn:
The number of bytes the host has read from the network.
特定一分鐘內,數據 "傳入(In)" 該節點的傳輸的 "總量",單位為 Bytes。

NetworkBandwidthInAllowanceExceeded:
The number of packets queued or dropped because the inbound aggregate bandwidth exceeded the maximum for the instance.
跟 NetworkBytesIn 有關,當 "特定一秒鐘" 若數據 "進入" 該節點的傳輸量 "瞬間超過" 該節點類型 "效能上限" 時,該指標就會增加。

!!! 簡單來說,當該實例 "效能上限" 為每秒 10 MB/s 時,若該秒鐘 "傳入(In)" 網路流量超過上限時,後面的封包就會等待、或是丟包。
----

NetworkBytesOut:
The number of bytes sent out on all network interfaces by the instance.
特定一分鐘內,數據 "傳出(Out)" 該節點的傳輸的 "總量",單位為 Bytes。

NetworkBandwidthOutAllowanceExceeded:
The number of packets queued or dropped because the outbound aggregate bandwidth exceeded the maximum for the instance.
跟 NetworkBytesOut 有關,當 "特定一秒鐘" 若數據 "傳出(Out)" 該節點的傳輸量 "瞬間超過" 該節點類型 "效能上限" 時,該指標就會增加。

!!! 簡單來說,當該實例 "效能上限" 為每秒 10 MB/s 時,若該秒鐘 "傳出" 網路流量超過上限時,後面的封包就會等待、或是丟包。
---

## 其他網路相關指標 ##
NetworkPacketsIn:
The number of packets received on all network interfaces by the instance. This metric identifies the volume of incoming traffic in terms of the number of packets on a single instance. Count

NetworkPacketsOut:
The number of packets sent out on all network interfaces by the instance. This metric identifies the volume of outgoing traffic in terms of the number of packets on a single instance.

NetworkConntrackAllowanceExceeded:
The number of packets dropped because connection tracking exceeded the maximum for the instance and new connections could not be established. This can result in packet loss for traffic to or from the instance.
Count

NetworkLinkLocalAllowanceExceeded:
The number of packets dropped because the PPS of the traffic to local proxy services exceeded the maximum for the network interface. This impacts traffic to the DNS service, the Instance Metadata Service, and the Amazon Time Sync Service.
Count

NetworkPacketsPerSecondAllowanceExceeded:
The number of packets queued or dropped because the bidirectional packets per second exceeded the maximum for the instance

案例分析一

特定節點,在短時間內(數秒鐘、或是數分鐘),有大量 “寫入 Write” 的行為,達到了該節點實例效能上限內,而導致客戶端(Redis Client)出現寫入延遲增加、寫入失敗、連線中斷(connection timeout)等等問題。

!!! 主要是要觀察指標 NetworkBytesIn/NetworkBandwidthInAllowanceExceeded ,是否在特定節點、或是特定時間有,有出現異常大量的數值。

NetworkBytesIn:
特定一分鐘內,數據 “傳入(In)” 該節點的傳輸的 “總量”,單位為 Bytes。

NetworkBandwidthInAllowanceExceeded:
跟 NetworkBytesIn 有關,當 “特定一秒鐘” 若數據 “進入” 該節點的傳輸量 “瞬間超過” 該節點類型 “效能上限” 時,該指標就會增加。

解決方案及建議:

一般來說,這跟客戶端(Redis Client)有直接的關係,所以改善方案,也以客戶端(Redis Client)為主。

  1. 在 Redis 集群最快的做法是,換大機型(Scaling Up),較大的機型有較高的網路效能上限,但這個效果是有限的。 請參考: Scaling ElastiCache for Redis clusters
  2. 在 Redis 集群去改用 “cluster mode enable 叢集模式”,用多個分片組(多個主節點),來支持大量的寫入行為。 請參考: Redis cluster mode and Key distribution
  3. 客戶端(Redis Client),將寫入行為去做分散。因為這樣 “大量的寫入”,一般是客戶端有 “排程” 寫入、例如每6個小時去後端拉大量資料,再去更新到 Redis 集群上,造成短暫的效能瓶頸。
  4. 客戶端(Redis Client),若有使用 Redis LUA 或是 Redis HASH 的方式,來存取數據,也有可能造成特定節點的問題。 解決建議,請參考: Redis Bigkey or Hotkey issue?

案例分析二

特定節點,在短時間內(數秒鐘、或是數分鐘),有大量 “讀取的操作 Redis” 的行為,達到了該節點實例效能上限內,而導致客戶端(Redis Client)出現讀讀取(Get)延遲增加、讀取失敗、連線中斷(connection timeout)等等問題。

!!! 這個狀態是 ElastiCache Redis 最常見遇到的,因為 ElastiCache 常用於讀取快取,所以一般是 “讀取 > 遠大於 > 寫入” 的使用方式。

!!! 主要是要觀察指標 NetworkBytesOut/NetworkBandwidthOutAllowanceExceeded ,是否在特定節點、或是特定時間有,有出現異常大量的數值。

NetworkBytesOut:
特定一分鐘內,數據 “傳出(Out)” 該節點的傳輸的 “總量”,單位為 Bytes。

NetworkBandwidthOutAllowanceExceeded:
跟 NetworkBytesOut 有關,當 “特定一秒鐘” 若數據 “傳出(Out)” 該節點的傳輸量 “瞬間超過” 該節點類型 “效能上限” 時,該指標就會增加。

解決方案及建議:

一般來說,這跟客戶端(Redis Client)也是有直接的關係,而大量讀取也是 ElastiCache 最常見的使用情境,此時會從 Redis 集群架構上的改善,會比較直接及有效的。

  1. 在 Redis 集群最快的做法是,換大機型(Scaling Up),較大的機型有較高的網路效能上限,但這個效果是有限的。 請參考: Scaling ElastiCache for Redis clusters
  2. 在 Redis 叢集模式(cluster mode enable )下,增加分片組(Scaling Out),也是可以考慮的,也比較建議。請參考: Scaling ElastiCache for Redis clusters
  3. 若是客戶端(Redis Client)有實做 “讀寫分離” 的話,那麼增加只讀副本節點(Adding replica nodes),是最佳的建議。用較多個副本節點來分散 “讀取(GET)” 來查詢量,是最有效、最直接的做法。 請參考: Adding a read replica, for Redis
  4. 客戶端(Redis Client) 改善方式,請參考 Redis 官方文檔的建議: Redis client handling優先考量是實做 “讀寫分離”

案例分析三

特定節點,在短時間內(數秒鐘、或是數分鐘),出現 NetworkConntrackAllowanceExceeded (連接跟蹤超過實例的最大值且無法建立新連接而丟棄的數據包) 這個指標。

NetworkConntrackAllowanceExceeded:
由於超過了分配給節點的、跨所有安全組跟蹤的連接最大數量而形成的數據包。在此期間,新連接可能會失敗。

造成這個問題主要的可能原因如下:

  1. Redis 集群有使用安全組,去限制來源連線 IP 的檢查。
Ingress rules:
---
TCP 6379 172.31.0.0/16
---

2. 並且在短時間內,有大量 “新增連線” 建立,而達到該實例類型的上限。

3. 並且客戶端(Redis client)都是使用 “短連接”,沒有使用連接池(Connection pool),所產生 “大量的新增連線 NewConnections”。

解決方案及建議:

  1. 在 Redis 集群最快的做法是,換大機型(Scaling Up),較大的機型有較高的網路效能上限,但這個效果是有限的。 請參考: Scaling ElastiCache for Redis clusters
  2. 移除安全組的跟蹤的連接限制,但這個方案,並不建議(安全性降低)。
Ingress rules:
---
TCP 6379 172.31.0.0/16 --> TCP 6379 0.0.0.0/0
---

3. 客戶端(redis client),改使用 “連接池(Connection Pooling)”,來降低短連接所造成的問題,此是最佳的作法。請參考: Redis client handling

!!補充說明!!
連接池(Connection Pooling)的原理,通過預先創建多個連接,當進行redis操作時, 直接獲取已經創建的連接進行操作,而且操作完成後,不會釋放,用於後續的其他redis操作,這樣就達到了避免頻繁的redis連接建立、釋放連接的開銷,從而提高性能。

換大機型(Scaling Up)

較大的機型有較高的網路效能上限,簡單來說,就是允許進出的 “網路介面 (eni)/網卡” 的水管變大了,自然卡到瓶頸的機率就降低了。

--

--

Jerry’s Notes
What’s next?

An cloud support engineer focus on troubleshooting with customer reported issue ,and cloud solution architecture.