本文說明暫停和停止的虛擬機器 (VM) 執行個體待命集區運作方式,以及如何使用待命集區加速代管執行個體群組 (MIG) 的擴充作業。
事前準備
- 詳閱這篇簡介頁面,瞭解 MIG 中已暫停和已停止的 VM。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
Terraform
如要在本機開發環境中使用本頁的 Terraform 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
詳情請參閱 Set up authentication for a local development environment。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
使用 MIG API 進行自動調度
建議您使用 Compute Engine 自動調度器,自動調度 MIG。不過,如果基於某些原因,您偏好使用其他自動調整程式,請使用 MIG API 的端點處理暫停和停止的 VM。
選擇要暫停或停止集區
選擇暫停或停止集區取決於您的特定用途。為獲得最佳效能,您應針對擴大部署情境實驗不同待命集區類型,判斷哪種最符合需求。不同工作負載可能會顯示較短的服務時間,但選項不同。 在某些情況下,將記憶體狀態從儲存空間複製到 VM 的作業,可能比重新啟動 VM 或從頭建立新 VM 更耗時。
如要找出最佳方法,請先參閱下列指南:
- 如果 VM 需要耗時的記憶體初始化作業,請使用已暫停的 VM,因為這類 VM 會保留記憶體狀態。確認應用程式可以暫停及繼續。 保留記憶體狀態需要額外儲存空間,可能會產生額外費用。
- 如果 VM 初始化作業主要著重於初始化儲存在永久磁碟中的資料,請使用已停止的 VM。
編輯 MIG 中的待命政策
本節說明如何設定待命集區模式,以擴大集區和初始延遲。
主控台
前往 Trusted Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要編輯的執行個體群組名稱。
按一下「編輯」,修改這個代管執行個體群組。
按一下「進階選項」展開該部分。
在「待命集區」部分中,選取「擴充」。
在「Initial delay」(初始延遲) 欄位中,輸入 MIG 暫停或停止 VM 前應等待的秒數。初始延遲時間可讓初始化指令碼準備 VM,以便快速擴充。
按一下 [儲存]。
gcloud
使用
instance-groups managed update
指令,並指定作業模式和初始延遲。gcloud compute instance-groups managed update MIG_NAME \ --standby-policy-mode=scale-out-pool \ --standby-policy-initial-delay=DELAY \ [--region=REGION | --zone=ZONE]
更改下列內容:
MIG_NAME
:MIG 的名稱。DELAY
:MIG 暫停或停止 VM 前應等待的秒數。初始延遲時間可讓初始化指令碼準備 VM,以便快速擴充。REGION
:如果是區域 MIG,則為 MIG 所在的區域。ZONE
:如果是可用區 MIG,則為 MIG 所在的可用區。
Terraform
下列範例會建立具有待命政策的可用區 MIG。使用
standby_policy
區塊設定初始延遲,並將模式設為SCALE_OUT_POOL
。本範例使用
google_compute_instance_group_manager
資源。如果是區域 MIG,請使用google_compute_region_instance_group_manager
資源。如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
REST
使用
instanceGroupManager.patch
方法,並在要求主體中指定作業模式和初始延遲時間。如果是區域 MIG,請使用regionInstanceGroupManager.patch
方法。PATCH https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME { // ... "standbyPolicy": { "mode": "SCALE_OUT_POOL", "initialDelaySec": DELAY } // ... }
更改下列內容:
PROJECT_ID
:專案 ID。ZONE
:如果是可用區 MIG,則為 MIG 所在的可用區。- 如果是區域 MIG,請將
zones/ZONE
替換為regions/REGION
,並指定 MIG 的區域。
- 如果是區域 MIG,請將
MIG_NAME
:MIG 的名稱。DELAY
:MIG 暫停或停止 VM 前應等待的秒數。初始延遲時間可讓初始化指令碼準備 VM,以便快速擴充。
調整 MIG 中的待命集區大小
本節說明如何調整 MIG 中暫停和停止 VM 的待命集區大小。
主控台
前往 Trusted Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要編輯的執行個體群組名稱。
按一下「編輯」,修改這個代管執行個體群組。
按一下「進階選項」展開該部分。
在「待命集區」部分,於「已暫停的 VM」和「已停止的 VM」欄位中輸入新大小。
按一下 [儲存]。
gcloud
使用
instance-groups managed update
指令,並加上--suspended-size
和--stopped-size
旗標。gcloud compute instance-groups managed update MIG_NAME \ --suspended-size=SUSPENDED_SIZE \ --stopped-size=STOPPED_SIZE \ [--region=REGION | --zone=ZONE]
更改下列內容:
MIG_NAME
:要暫停執行個體的 MIG 名稱。SUSPENDED_SIZE
:MIG 在任何指定時間應維護的暫停 VM 數量。STOPPED_SIZE
:MIG 在任何指定時間應維持的已停止 VM 數量。REGION
:如果是區域 MIG,則為 MIG 所在的區域。ZONE
:如果是可用區 MIG,則為 MIG 所在的可用區。
Terraform
下列範例會建立可用區 MIG,並為暫停和停止的 VM 設定目標大小。如要設定目標大小,請使用
target_suspended_size
和target_stopped_size
引數。本範例使用
google_compute_instance_group_manager
資源。如果是區域 MIG,請使用google_compute_region_instance_group_manager
資源。如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
REST
使用
instanceGroupManager.patch
方法,並在要求主體中指定已暫停和已停止 VM 集區的大小。如果是區域 MIG,請使用regionInstanceGroupManager.patch
方法。PATCH https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME { // ... "targetSuspendedSize": SUSPENDED_SIZE, "targetStoppedSize": STOPPED_SIZE // ... }
更改下列內容:
PROJECT_ID
:專案 ID。ZONE
:如果是可用區 MIG,則為 MIG 所在的可用區。- 如果是區域 MIG,請將
zones/ZONE
替換為regions/REGION
,並指定 MIG 的區域。
- 如果是區域 MIG,請將
MIG_NAME
:要停止執行個體的 MIG 名稱。SUSPENDED_SIZE
:MIG 在任何指定時間應維護的暫停 VM 數量。STOPPED_SIZE
:MIG 在任何指定時間應維持的已停止 VM 數量。
後續步驟
- 瞭解如何手動暫停或停止 MIG 中的 VM。
- 進一步瞭解MIG 中已暫停和停止的 VM 更新。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["\u003cp\u003eThis document outlines the functionality of the standby pool for suspended and stopped virtual machine (VM) instances, enabling accelerated scale-out for managed instance groups (MIGs).\u003c/p\u003e\n"],["\u003cp\u003eUsers can leverage the MIG API, which can be used to integrate with custom autoscalers or with Google Kubernetes Engine (GKE) autoscaler for faster scaling using the standby pool of VMs.\u003c/p\u003e\n"],["\u003cp\u003eThe document provides guidance on choosing between suspended and stopped VMs based on initialization needs, suggesting that suspended VMs are best for time-consuming memory initialization, while stopped VMs are better for data-focused persistent disk initialization.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure the standby policy within a MIG using the console, gcloud CLI, Terraform, or REST API, allowing for customization of the initial delay before VMs are suspended or stopped, which helps to prepare VMs for quicker scale-out.\u003c/p\u003e\n"],["\u003cp\u003eThe standby pool can be resized to manage the number of suspended and stopped VMs using the console, gcloud CLI, Terraform, or REST API, allowing you to set the target numbers for each type of VM.\u003c/p\u003e\n"]]],[],null,[]] -