本文件說明如何建立兩個 VM,並來回傳送流量,以便觀察網路效能,進而測試各 VM 的 Tier_1 網路效能。如要充分利用這項功能,您必須使用支援 Google Virtual NIC (gVNIC) 的作業系統建立 VM。為各 VM 啟用 Tier_1 網路效能需要較大的 VM 大小,因此請確認您有足夠的 CPU 配額可建立 VM。
事前準備
- 請確認您使用的是公開的支援 gVNIC 的映像檔,或是在專案中建立自訂映像檔。
- 請確認您已建立 VPC 防火牆規則,允許透過通訊埠 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
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
設定基準測試 VM
建立兩部 n2-standard-64
vCPU 機器,並啟用各 VM Tier_1 網路效能和最高的最大傳輸單位 (MTU) 設定。這樣一來,VM 的最大輸出頻寬 (使用內部 IP) 可達 75 Gbps。
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 必須位於同一個可用區和同一個 VPC 網路。在基準測試期間,這兩個 VM 會對虛擬私有雲網路路徑進行雙向測試。
確認 MTU 設定
在其中一個 VM 的來賓作業系統中使用 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 網路服務的定價。
- 如需其他機器類型,請參閱頻寬層級。