查看可見的 CPU 核心數量


本文件說明如何查看虛擬機器 (VM) 執行個體的可見 CPU 核心數量。

查看 VM 詳細資料時,您可以確認 VM 是否有預設的顯示 CPU 核心數量,或是否已自訂這個數量。減少 VM 可見的 CPU 核心數量,有助於降低授權費用,且不會降低 Persistent Disk 效能限制。不過,減少可見的 CPU 核心數量可能會影響網路效能。

事前準備

  • 如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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

    1. 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.

    2. 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 詳細資料所需的權限,請要求管理員為您授予 VM 或專案的 Compute Instance 管理員 (v1) (roles/compute.instanceAdmin.v1) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

這個預先定義的角色包含 compute.instances.get 權限,這是查看 VM 詳細資料所需的權限。

您或許還可透過自訂角色或其他預先定義的角色取得此權限。

查看 VM 的可見 CPU 核心數量

如要判斷是否為 VM 自訂可見的 CPU 核心數量,請選取下列其中一個選項:

主控台

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. 在「Name」欄中,按一下 VM 名稱。

    VM 的詳細資料頁面會隨即開啟,並選取「Details」分頁標籤。

  3. 在「機器設定」部分,檢查「自訂可見核心」的值。如果沒有顯示任何值,則 VM 會使用可見 CPU 核心的預設數量

gcloud

如要查看 VM 的詳細資料,請使用 gcloud compute instances describe 指令

gcloud compute instances describe VM_NAME \
    --zone=ZONE

更改下列內容:

  • VM_NAME:VM 名稱。

  • ZONE:VM 所在區域。

如果您自訂了 VM 的可見 CPU 核心數量,輸出內容就會包含 visibleCoreCount 欄位,如下所示:

advancedMachineFeatures:
  visibleCoreCount: VISIBLE_CORE_COUNT
...

如果輸出內容不含 visibleCoreCount 欄位,表示 VM 具有可見 CPU 核心的預設數量

REST

如要查看 VM 的詳細資料,請對 instances.get 方法發出 GET 要求。

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME

更改下列內容:

  • PROJECT_ID:VM 所在專案的 ID。

  • ZONE:VM 所在區域。

  • VM_NAME:VM 名稱。

如果您自訂了 VM 的可見 CPU 核心數量,輸出內容就會包含 visibleCoreCount 欄位,如下所示:

{
  ...
  "advancedMachineFeatures": {
    visibleCoreCount: VISIBLE_CORE_COUNT
  },
  ...
}

如果輸出內容不含 visibleCoreCount 欄位,表示 VM 具有可見 CPU 核心的預設數量

後續步驟