本文說明如何建立兩個 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 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI。 安裝完成後,執行下列指令初始化 Google Cloud CLI:
gcloud init
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。 安裝完成後,執行下列指令初始化 Google Cloud CLI:
gcloud init
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using 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_NAME/global/images/IMAGE_NAME \ --network=NETWORK_NAME \ --network-interface=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 的可用區。兩部 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 的可用區。兩部 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 網路定價。
- 如需其他機器類型,請參閱頻寬層級。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-29 (世界標準時間)。
-