為 VM 執行個體設定較高的網路頻寬基準

本文說明如何建立兩個 VM,並來回串流流量,藉此測試各 VM 的 Tier_1 網路效能,如要使用這項功能,您必須使用支援 Google Virtual NIC (gVNIC)作業系統建立 VM。各 VM 的 Tier_1 網路效能需要較大的 VM 大小,因此請確認您有足夠的 CPU 配額來建立 VM。

事前準備

  • 請確認您是否使用支援 gVNIC 的公開映像檔,或在專案中建立自訂映像檔
  • 確認您已建立虛擬私有雲防火牆規則,允許在 TCP 通訊埠 5001 或您選擇的其他通訊埠輸入,以進行iperf效能測試。
  • 請使用 iPerf 第 2 版 (而非第 3 版) 執行基準化作業。
  • 如果尚未設定驗證,請先完成設定。 驗證可確認您的身分,以便存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:

    選取這個頁面上的分頁,瞭解如何使用範例:

    控制台

    使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,無須設定驗證。

    gcloud

    1. 安裝 Google Cloud CLI。 完成後,執行下列指令來初始化 Google Cloud CLI:

      gcloud init

      若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  • 設定預設地區和區域
  • REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI。

      若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

    詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」。

設定 VM 以進行基準化

建立兩部 n2-standard-64 vCPU 機器,並為各 VM 啟用 Tier_1 網路效能,以及最高的最大傳輸單位 (MTU) 設定。這可讓 VM 享有最高 75 Gbps 的輸出頻寬上限 (使用內部 IP)。

gcloud

  1. 如要建立映像檔,請使用 gcloud compute images create 指令

      gcloud compute images create IMAGE_NAME \
       --project=PROJECT_ID \
       --source-image-family=SOURCE_IMAGE_FAMILY \
       --source-image-project=SOURCE_IMAGE_PROJECT \
       --guest-os-features=GVNIC
    

    更改下列內容:

    • PROJECT_ID:專案名稱。
    • IMAGE_NAME:要建立的映像檔名稱。
    • SOURCE_IMAGE_FAMILY:公開映像檔的必要版本。請使用 ubuntu-2004-lts 進行這項測試。
    • SOURCE_IMAGE_PROJECT:包含來源圖片的專案名稱。請使用 ubuntu-os-cloud 進行這項測試。

    範例

    gcloud compute images create benchmark-image-test \
      --project=my-project \
      --source-image-family=ubuntu-2004-lts \
      --source-image-project=ubuntu-os-cloud \
      --guest-os-features=GVNIC
    
  2. 建立使用最大 MTU 設定的自動模式虛擬私有雲網路:

      gcloud compute networks create NETWORK_NAME \
      --project=PROJECT_ID \
      --subnet-mode=AUTO --mtu=8896
    

    更改下列內容:

    • PROJECT_ID:專案名稱。
    • NETWORK_NAME:網路名稱。
  3. 建立兩個相同的執行個體:

      gcloud compute instances create \
          VM_NAME_1 VM_NAME_2 \
          --project=PROJECT_ID \
          --zone=ZONE \
          --machine-type=n2-standard-64 \
          --image=projects/PROJECT_NAME/global/images/IMAGE_NAME \
          --network=NETWORK_NAME \
          --network-interface=nic-type=GVNIC \
          --network-performance-configs=total-egress-bandwidth-tier=TIER_1
    

    更改下列內容:

    • VM_NAME_1VM_NAME_2:要建立的 VM 執行個體名稱。
    • PROJECT_ID:您的專案名稱。
    • ZONE:VM 的可用區。兩部 VM 必須位於同一可用區。
    • PROJECT_NAME/global/images/IMAGE_NAME:您的專案名稱和映像檔名稱。
    • NETWORK_NAME:您設定的網路名稱,且 MTU 設定為上限。

執行基準測試

這兩部 VM 必須位於同一個可用區和同一個 虛擬私有雲網路。在基準測試期間,這兩個 VM 會對虛擬私有雲網路路徑進行雙向測試。

驗證 MTU 設定

使用其中一個 VM 的客層 OS 中的 ifconfig,確認虛擬私有雲 (VPC) 網路已設定最大 MTU。

  1. 連線至其中一個 VM

  2. 在終端機視窗中執行下列指令:

     /sbin/ifconfig | grep mtu
    

    回報的 MTU 應為 8896。

     ens4: flags=4163  mtu 8896
     lo: flags=73  mtu 65536
    

驗證 VM 設定

檢查虛擬機器屬性,確認虛擬機器已啟用 Tier_1 網路。

gcloud

如要查看執行個體,請使用 gcloud compute instances describe 指令

gcloud compute instances describe VM_NAME_1 \
    --project=PROJECT_ID \
    --zone=ZONE \
    --format="text(networkPerformanceConfig)"
gcloud compute instances describe VM_NAME_2 \
    --project=PROJECT_ID \
    --zone=ZONE \
    --format="text(networkPerformanceConfig)"

更改下列內容:

  • VM_NAME_1:要查看的 VM 執行個體名稱。
  • VM_NAME_2: 要查看的 VM 執行個體名稱。
  • PROJECT_ID:您的專案名稱。
  • ZONE:VM 的可用區。兩個 VM 必須位於同一可用區。

回應內容應如下所示:

networkPerformanceConfig.totalEgressBandwidthTier: TIER_1

使用 iPerf 在 Debian 系統上執行基準測試

gcloud

  1. 如果尚未完成,請按照「設定 VM 以進行基準化測試」一文中的步驟操作。

  2. 兩個 VM 執行個體都啟動後,請使用 SSH 連線至其中一個 VM。

    gcloud compute ssh VM_NAME_1 \
      --project=PROJECT_ID
    

    更改下列內容:

    • VM_NAME_1:第一個 VM 的名稱。
    • PROJECT_ID:您的專案名稱。
  3. 在第一個 VM 上完成下列步驟:

    1. 安裝「iperf」。

      sudo apt-get update && sudo apt-get install iperf
      
    2. 取得這個 VM 的內部 IP 位址。請記下內部 IP 位址,稍後會用到。

      ip a
      
    3. 啟動 iPerf 伺服器。

      iperf -s
      

      這會啟動伺服器,監聽連線以執行基準測試。在測試期間,請讓 iPerf 伺服器保持執行狀態。

  4. 在另一個用戶端終端機中,使用 SSH 連線至第二個 VM。

    gcloud compute ssh VM_NAME_2 \
       --project=PROJECT_ID
    

    更改下列內容:

    • VM_NAME_2:第二部 VM 的名稱。
    • PROJECT_ID:您的專案名稱。
  5. 在第二部 VM 上,完成下列步驟:

    1. 安裝 iPerf。

      sudo apt-get update && sudo apt-get install iperf
      
    2. 執行 iperf 測試,並將第一個 VM 的 IP 位址指定為目標。

      iperf -t 30 -c internal_ip_of_instance_1 -P 16
      

      這會執行 30 秒的測試。如果 iPerf 無法連線至其他 VM,您可能需要調整 VM 上的網路或防火牆設定,或是在 Google Cloud 控制台中進行調整。

      結果應如下列範例所示。 這表示啟用 Tier_1 網路後,n2-standard-64 的輸出頻寬上限為 75 Gbps,超過預設的 32 Gbps 輸出頻寬上限。

      ------------------------------------------------------------
      Client connecting to 10.128.0.10, TCP port 5001
      TCP window size: 1.59 MByte (default)
      ------------------------------------------------------------
      [ 12] local 10.128.0.11 port 57722 connected with 10.128.0.10 port 5001
      [ 11] local 10.128.0.11 port 57720 connected with 10.128.0.10 port 5001
      [ 16] local 10.128.0.11 port 57730 connected with 10.128.0.10 port 5001
      [  6] local 10.128.0.11 port 57710 connected with 10.128.0.10 port 5001
      [ 13] local 10.128.0.11 port 57724 connected with 10.128.0.10 port 5001
      [  8] local 10.128.0.11 port 57712 connected with 10.128.0.10 port 5001
      [  9] local 10.128.0.11 port 57716 connected with 10.128.0.10 port 5001
      [ 14] local 10.128.0.11 port 57726 connected with 10.128.0.10 port 5001
      [ 15] local 10.128.0.11 port 57728 connected with 10.128.0.10 port 5001
      [ 10] local 10.128.0.11 port 57718 connected with 10.128.0.10 port 5001
      [  4] local 10.128.0.11 port 57706 connected with 10.128.0.10 port 5001
      [  5] local 10.128.0.11 port 57708 connected with 10.128.0.10 port 5001
      [  3] local 10.128.0.11 port 57704 connected with 10.128.0.10 port 5001
      [ 17] local 10.128.0.11 port 57732 connected with 10.128.0.10 port 5001
      [  7] local 10.128.0.11 port 57714 connected with 10.128.0.10 port 5001
      [ 18] local 10.128.0.11 port 57734 connected with 10.128.0.10 port 5001
      [ ID] Interval       Transfer     Bandwidth
      [ 12]  0.0-30.0 sec  7.63 GBytes  2.19 Gbits/sec
      [ 11]  0.0-30.0 sec  17.7 GBytes  5.07 Gbits/sec
      [ 16]  0.0-30.0 sec  9.15 GBytes  2.62 Gbits/sec
      [  6]  0.0-30.0 sec  43.8 GBytes  12.6 Gbits/sec
      [ 13]  0.0-30.0 sec  23.6 GBytes  6.76 Gbits/sec
      [  8]  0.0-30.0 sec  13.3 GBytes  3.80 Gbits/sec
      [  9]  0.0-30.0 sec  9.29 GBytes  2.66 Gbits/sec
      [ 14]  0.0-30.0 sec  19.6 GBytes  5.62 Gbits/sec
      [ 15]  0.0-30.0 sec  12.5 GBytes  3.58 Gbits/sec
      [ 10]  0.0-30.0 sec  11.1 GBytes  3.19 Gbits/sec
      [  4]  0.0-30.0 sec  19.0 GBytes  5.43 Gbits/sec
      [  5]  0.0-30.0 sec  7.32 GBytes  2.10 Gbits/sec
      [  3]  0.0-30.0 sec  8.78 GBytes  2.51 Gbits/sec
      [ 17]  0.0-30.0 sec  17.5 GBytes  5.02 Gbits/sec
      [  7]  0.0-30.0 sec  33.4 GBytes  9.57 Gbits/sec
      [ 18]  0.0-30.0 sec  7.64 GBytes  2.19 Gbits/sec
      [SUM]  0.0-30.0 sec   261 GBytes  74.9 Gbits/sec
      

基準測試後移除資源

移除基準測試期間建立的資源,以免產生映像檔和額外 VM 的費用。

gcloud

  1. 使用 gcloud compute instances delete 指令移除您為基準測試建立的執行個體。

    gcloud compute instances delete \
      VM_NAME_1 VM_NAME_2 \
       --project=PROJECT_ID \
       --zone=ZONE
    

    更改下列內容:

    • VM_NAME_1VM_NAME_2:要刪除的兩個 VM 執行個體名稱。
    • PROJECT_ID:您的專案名稱。
    • ZONE:VM 的可用區。兩部 VM 應位於相同區域。
  2. 使用 gcloud compute networks delete 指令移除您為基準測試建立的網路。

    gcloud compute networks delete NETWORK_NAME  \
       --project=PROJECT_ID
    

    更改下列內容:

    • NETWORK_NAME:要刪除的網路名稱。
    • PROJECT_ID:您的專案名稱。
  3. 使用 gcloud compute images delete 指令移除您為基準測試建立的映像檔。

     gcloud compute images delete IMAGE_NAME  \
        --project=PROJECT_ID
    

    更改下列內容:

    • IMAGE_NAME:要刪除的映像檔名稱。
    • PROJECT_ID:您的專案名稱。

後續步驟