計算互連網路的網路總處理量

本教學課程說明如何計算網路輸送量,包括Google Cloud 內部,以及連線至地端或第三方雲端位置 (使用 Cloud Interconnect 連線)。本文說明如何分析結果、列出可能影響網路效能的變數,並提供一些疑難排解提示。

限制和注意事項

  • 須遵守 Cloud Interconnect 限制。詳情請參閱「Cloud Interconnect 配額」。
  • 網路介面卡限制: Google Cloud 考量每個虛擬機器 (VM) 執行個體的頻寬,而非每個網路介面 (NIC) 或 IP 位址。VM 的機器類型會定義其最高輸出速率,但只有在特定情況下才能達到該速率。如要瞭解各機器類型的 vCPU 數量,請參閱這份表格
  • 路徑中的其他裝置 (防火牆、緩衝區較小的交換器,以及其他供應商的裝置) 和相關限制也適用。請執行下列工作,以減輕這些限制的影響。

    • 收集路徑中防火牆和交換器的網路統計資料。
    • 如要測試 Cloud Interconnect,請盡可能略過地端主機和 Google Edge 裝置之間的裝置。
    • 找出並驗證本地網路與 Google Cloud VM 之間路徑中的所有裝置,確認是否可能導致輸送量問題。

網路總處理量評估工具總覽

本教學課程將示範如何使用下列工具計算網路輸送量:

  • iPerf3:網路測試工具,可建立 TCP/UDP 資料串流 (單一或多個執行緒),並測量傳輸該資料串流的網路總處理量。

    注意:iPerf3 僅適用於單一 CPU 的電腦。

  • Netperf:類似 iPerf3 的工具,但適用於多 CPU 執行個體的輸送量測試,這些執行個體在單一 CPU 上受 CPU 限制。

  • tcpdump:指令列封包分析器,可擷取封包詳細資料和 TCP/IP 通訊,以進行更進階的疑難排解。tcpdump 工具可與其他工具 (例如 Wireshark) 搭配使用。

  • Netstat:指令列網路公用程式,可顯示傳輸控制通訊協定的網路連線 (包括傳入和傳出)、轉送表,以及多個網路介面 (網路介面控制器或軟體定義的網路介面) 和網路通訊協定統計資料。

  • mtr:網路診斷工具,可執行 traceroute 和 ping 函式。這項工具會限制個別封包可經過的躍點數量,藉此探查路徑上的路由器,並監聽逾時回應。

使用 iPerf3 測量總處理量

請按照這個程序,測量單一 VM 執行個體的處理量。

選擇大型機型

如要執行輸送量測試,請使用大型機器類型,例如 n1-standard-8。 這個機器類型的輸出總處理量上限為 16 Gbps,因此每個 VM 的輸出總處理量不會干擾測試。

安裝工具

在 Linux VM 執行個體上安裝 iPerf3、mtr、netstat 和 tcpdump

如為以 Debian 為基礎的發行版本,請執行下列指令:

    sudo apt-get update
    sudo apt-get install iperf3 tcpdump mtr netstat

如為 Redhat 型發行版本,請執行下列指令:

    yum update
    yum install iperf3 tcpdump mtr netstat

安裝 netperf

如為以 Debian 為基礎的發行版本,請執行下列指令:

    sudo apt-get install git build-essential autoconf texinfo -y
    git clone https://github.com/HewlettPackard/netperf.git
    cd netperf
    ./autogen.sh
    ./configure --enable-histogram --enable-demo=yes
    make
    cp src/netserver ~/.local/bin
    cp src/netperf ~/.local/bin

如為 Redhat 型發行版本,請執行下列指令:

    sudo yum install git build-essential autoconf texinfo -y
    git clone https://github.com/HewlettPackard/netperf.git
    cd netperf
    ./autogen.sh
    ./configure --enable-histogram --enable-demo=yes
    make
    cp src/netserver ~/.local/bin
    cp src/netperf ~/.local/bin

執行必要條件測試

  1. 請確認 VLAN 連結大小設定正確無誤。詳情請參閱「修改 VLAN 連結」。
  2. 在連線的兩端 (每個終端機),執行 tophtop 指令,監控 CPU 使用率。
  3. 執行任何測試前,請先使用 netstat 指令收集網路統計資料。

    netstat -s >> netstat.log
    
  4. 在另一個終端機中,先執行 tcpdump 指令,然後再使用 snaplen 參數值 128 擷取任何內容。

    在兩個端點上執行這個指令。

    sudo /usr/sbin/tcpdump -s 128 -i [DEVICE_INTERFACE] host [IP_ADDRESS of remote side] -w mycap.pcap
    
  5. 取得來源和目的地主機的讀取和寫入記憶體大小。

    $ sysctl net.ipv4.tcp_rmem
    $ sysctl net.ipv4.tcp_wmem
    $ sysctl net.core.rmem_max
    $ sysctl net.core.rmem_default
    $ net.core.wmem_max
    $ net.core.wmem_default
    $ uname -r
    $ cat /etc/os-release
    

執行 iperf3 測試

建議您執行多個並行 iperf3 測試串流。建議您至少執行四項測試,最多執行十項測試,以取得實用結果。

  1. 在另一個終端機中,於連線的一端 (VM 或地端部署機器) 執行 iperf3 伺服器。如要使用多個串流,需要多個 iperf3 伺服器。

  2. 執行 iPerf3 工具,並加上 udp 標記,測試 Cloud Interconnect。如果已達到所選的 UDP 輸送量,請執行進一步的疑難排解步驟。

  3. 如要從指令列執行多個 iperf3 伺服器,請執行下列指令:

    $ iperf3 -s -p 5101&; iperf3 -s -t 30 -p 5102&; iperf3 -s  -p 5103 &
    
  4. 使用下列 bash 指令碼執行多個 iperf3 伺服器:

    #!/bin/bash
    #start iperf3 server running in background
    
    for i in `seq 0 9`;
    do
            iperf3 -s  -B 10.0.100.35 -t 30 -u -p 521$i &
    done
    

iperf3 client 預設會執行 10 秒,這可能不足以讓 TCP 達到最大處理量。將 DURATION 值設為至少 30 秒,爭取更可靠的結果。

    iperf3 -c [server IP address] -P [THREADS] -t [DURATION]

執行多個 iperf3 UDP 串流的 Bash 指令碼

echo "UDP iperf test - 10 streams"
for i in `seq 0 9`;
do
       iperf3 -B 10.0.100.35 -c 192.168.50.3 --logfile ~/gcpvm_client-521$i.log -u -b 1G  -l 1390 -t10 -p 521$i    &

done

執行多個 iperf3 TCP 串流的 Bash 指令碼

echo "UDP iperf test - 10 streams"
for i in `seq 0 9`;
do
       iperf3 -B 10.0.100.35 -c 192.168.50.3 --logfile ~/gcpvm_client-521$i.log -b 1G  -l 1390 -t10 -p 521$i    &

done

iperf3 測試執行期間,請監控兩部裝置的 CPU 負載。 如果 CPU 負載接近 100%,表示 CPU 是 iperf3 執行緒的效能瓶頸。 在這種情況下,請使用 Netperf 工具,因為該工具支援多個 CPU。

如果無法執行 Netperf,可以同時在不同終端機和不同連接埠上啟動多個 iPerf3 伺服器和用戶端。

分析測試結果

請按照下列步驟操作。

  1. 檢查 iperf3 用戶端結果,瞭解頻寬和封包遺失情形。
  2. 檢查 iperf3 伺服器結果,確認是否有任何封包順序錯誤。
  3. 執行封包擷取分析。 執行下列指令,將 pcap 檔案轉換為文字檔。

    tcpdump -A -[PCAP-FILENAME].pcap > [TXT-FILENAME].txt
    
  4. 執行下列指令,取得封包總數和亂序封包。

    grep -e "Total" -A1 pcap [TXT-FILENAME]
    

    輸出內容如下:

    gcpvm-send-5210.txt:Total UDP packets: 874032
    gcpvm-send-5210.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5211.txt:Total UDP packets: 791218
    gcpvm-send-5211.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5212.txt:Total UDP packets: 961510
    gcpvm-send-5212.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5213.txt:Total UDP packets: 961517
    gcpvm-send-5213.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5214.txt:Total UDP packets: 961501
    gcpvm-send-5214.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5215.txt:Total UDP packets: 961521
    gcpvm-send-5215.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5216.txt:Total UDP packets: 889932
    gcpvm-send-5216.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5217.txt:Total UDP packets: 961483
    gcpvm-send-5217.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5218.txt:Total UDP packets: 961479
    gcpvm-send-5218.txt:Total out-of-order packets: 0, missing packets: 0
    gcpvm-send-5219.txt:Total UDP packets: 961518
    gcpvm-send-5219.txt:Total out-of-order packets: 0, missing packets: 0
    

    以下分析結果顯示效能測試期間的封包遺失情形:

    $ grep -e "Total" -A1 onPrem-send-*.txt
    

    輸出內容如下:

    "Total" -A1 onPrem-send-*.txt
    onPrem-send-5210.txt:Total UDP packets: 858698
    onPrem-send-5210.txt:Total out-of-order packets: 0, missing packets: 5408
    --
    onPrem-send-5211.txt:Total UDP packets: 857667
    onPrem-send-5211.txt:Total out-of-order packets: 0, missing packets: 4929
    --
    onPrem-send-5212.txt:Total UDP packets: 857126
    onPrem-send-5212.txt:Total out-of-order packets: 0, missing packets: 5349
    --
    onPrem-send-5213.txt:Total UDP packets: 857424
    onPrem-send-5213.txt:Total out-of-order packets: 0, missing packets: 5495
    --
    onPrem-send-5214.txt:Total UDP packets: 857139
    onPrem-send-5214.txt:Total out-of-order packets: 0, missing packets: 4692
    --
    onPrem-send-5215.txt:Total UDP packets: 857175
    onPrem-send-5215.txt:Total out-of-order packets: 0, missing packets: 4789
    --
    onPrem-send-5216.txt:Total UDP packets: 857104
    onPrem-send-5216.txt:Total out-of-order packets: 0, missing packets: 5196
    --
    onPrem-send-5217.txt:Total UDP packets: 857122
    onPrem-send-5217.txt:Total out-of-order packets: 0, missing packets: 5423
    --
    onPrem-send-5218.txt:Total UDP packets: 857383
    onPrem-send-5218.txt:Total out-of-order packets: 0, missing packets: 5283
    --
    onPrem-send-5219.txt:Total UDP packets: 857313
    onPrem-send-5219.txt:Total out-of-order packets: 0, missing packets: 4934
    
  5. 存取裝置頁面,查看連接埠的輸送量。

  6. 如果 netstat 輸出內容顯示讀取/寫入錯誤,可能需要調整 TCP/UDP 大量流量。

  7. 如有封包順序錯誤,應在 VPN 閘道中擷取封包,以利進一步分析。 如要進一步瞭解如何在 VPN 閘道中執行封包擷取作業,請開啟支援案件

  8. 如果 iperf3 UDP 測試達到所需輸送量,問題一定出在其他地方,可能需要調整 TCP。