本文說明如何建立兩個 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
-
安裝 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
如要建立映像檔,請使用 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建立使用最大 MTU 設定的自動模式虛擬私有雲網路:
gcloud compute networks create NETWORK_NAME \ --project=PROJECT_ID \ --subnet-mode=AUTO --mtu=8896
更改下列內容:
- PROJECT_ID:專案名稱。
- NETWORK_NAME:網路名稱。
建立兩個相同的執行個體:
gcloud compute instances create \ VM_NAME_1 VM_NAME_2 \ --project=PROJECT_ID \ --zone=ZONE \ --machine-type=n2-standard-64 \ --image=projects/PROJECT_ID/global/images/IMAGE_NAME \ --network-interface=network=NETWORK_NAME,nic-type=GVNIC \ --network-performance-configs=total-egress-bandwidth-tier=TIER_1更改下列內容:
- VM_NAME_1、VM_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。
在終端機視窗中執行下列指令:
/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 必須位於同一個可用區。
回應內容應如下所示:
networkPerformanceConfig.totalEgressBandwidthTier: TIER_1
使用 iPerf 在以 Debian 為基礎的系統上執行基準測試
gcloud
如果尚未完成,請按照「設定用於基準測試的 VM」一文中的步驟操作。
兩個 VM 執行完畢後,請使用 SSH 連線至其中一個 VM。
gcloud compute ssh VM_NAME_1 \ --project=PROJECT_ID
更改下列內容:
- VM_NAME_1:第一個 VM 的名稱。
- PROJECT_ID:您的專案名稱。
在第一個 VM 上完成下列步驟:
安裝
iperf。sudo apt-get update && sudo apt-get install iperf
取得這個 VM 的內部 IP 位址。記下內部 IP 位址,稍後會用到。
ip a
啟動 iPerf 伺服器。
iperf -s
這會啟動伺服器,監聽連線以執行基準測試。在測試期間,請讓 iPerf 伺服器保持運作。
在另一個用戶端終端機中,使用 SSH 連線至第二個 VM。
gcloud compute ssh VM_NAME_2 \ --project=PROJECT_ID
更改下列內容:
- VM_NAME_2:第二個 VM 的名稱。
- PROJECT_ID:您的專案名稱。
在第二部 VM 上,完成下列步驟:
安裝 iPerf。
sudo apt-get update && sudo apt-get install iperf
執行 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
使用
gcloud compute instances delete指令,移除您為基準測試建立的執行個體。gcloud compute instances delete \ VM_NAME_1 VM_NAME_2 \ --project=PROJECT_ID \ --zone=ZONE
更改下列內容:
- VM_NAME_1、VM_NAME_2: 要刪除的兩個 VM 執行個體名稱。
- PROJECT_ID:您的專案名稱。
- ZONE:虛擬機的可用區。兩部 VM 應位於同一個可用區。
使用
gcloud compute networks delete指令移除您為基準測試建立的網路。gcloud compute networks delete NETWORK_NAME \ --project=PROJECT_ID
更改下列內容:
- NETWORK_NAME:要刪除的網路名稱。
- PROJECT_ID:您的專案名稱。
使用
gcloud compute images delete指令移除為基準測試建立的映文件。gcloud compute images delete IMAGE_NAME \ --project=PROJECT_ID更改下列內容:
- IMAGE_NAME:要刪除的映文件名稱。
- PROJECT_ID:您的專案名稱。
後續步驟
- 瞭解 Tier_1 網路定價。
- 查看其他機型的頻寬級別。