Go 1.11 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Go 1.11 應用程式,即使貴機構先前使用機構政策重新啟用舊版執行階段的部署作業也一樣。現有的 Go 1.11 應用程式在
淘汰日期過後,仍會繼續執行並接收流量。建議您
遷移至最新支援的 Go 版本。
設定暖機要求以改善效能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在將應用程式的程式碼載入到新建立的執行個體時,您可以使用暖機要求來減少要求及回覆的延遲時間。
App Engine 經常需要將應用程式的程式碼載入至新的執行個體。載入執行個體作業可能會在發生以下情況時進行:
- 重新部署應用程式的版本時。
- 因要求的負載超過目前這組運作中執行個體的容量,而建立新的執行個體時。
- 基礎架構或實體硬體進行維護及修復時。
將應用程式的程式碼載入至新的執行個體時,可能會產生載入要求。
載入要求可能會讓使用者面臨的要求延遲時間增加,但可使用「暖機要求」來避免此延遲時間增加情形。暖機要求會在任何即時要求到達該執行個體前,先將您應用程式的程式碼載入至新的執行個體。
如果您的應用程式啟用了暖機要求,App Engine 會嘗試偵測應用程式何時需要新的執行個體,並發出暖機要求來初始化新的執行個體。然而,嘗試偵測的功能並非在每種情況下均能有效運作。因此,即使應用程式已啟用暖機要求,仍可能會產生載入要求。舉例來說,如果您的應用程式沒有提供流量,則向應用程式發出的第一個要求一律為載入要求,而非暖機要求。
如同其他所有向 App Engine 應用程式發出的要求,暖機要求也會計入執行個體時數。在大多數情況下,啟用暖機要求後,您不會發現執行個體時數增加,因為應用程式只是在暖機要求中初始化,而不是載入要求。如果您決定執行更多工作,例如在暖機要求期間預先快取,執行個體時數用量可能會增加。如果將 min_idle_instances
設為大於 0
,這些執行個體首次啟動時可能會遇到暖機要求,但之後會保持可用狀態。
啟用暖機要求
App Engine 排程器會使用暖機要求,並依據使用者提供的設定,控制執行個體的自動調整資源配置。App Engine 會在啟用暖機要求的情況下向 /_ah/warmup
發出 GET
要求。您可以針對這個要求實作處理常式,以執行應用程式專屬的工作,例如預先快取應用程式資料。
排程器判定需要更多執行個體時,就會啟動執行個體。由於排程器會使用暖機要求啟動執行個體,因此即使停用了暖機要求,這些要求仍可能會出現在記錄中。
請注意,系統不保證會呼叫暖機要求,並且在某些狀況下會改為傳送載入要求,例如:該執行個體為首先啟動的執行個體,或是流量發生遽增。然而,如果暖機要求已啟用,系統會「盡可能」嘗試將要求傳送至暖機完成的執行個體。
如要啟用暖機要求,請在 app.yaml
檔案的 inbound_services
指令下方新增 warmup
元素,例如:
inbound_services:
- warmup
建立處理常式
建立處理常式,處理傳送至 /_ah/warmup
的要求。處理常式應執行應用程式需要的任何暖機邏輯。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eWarmup requests reduce latency by loading your app's code into a new instance before live requests arrive, avoiding delays caused by loading requests.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine uses warmup requests to initialize new instances when needed, such as during redeployments, increased traffic, or infrastructure maintenance.\u003c/p\u003e\n"],["\u003cp\u003eWarmup requests are triggered by App Engine issuing \u003ccode\u003eGET\u003c/code\u003e requests to \u003ccode\u003e/_ah/warmup\u003c/code\u003e, and you can implement handlers for this endpoint to perform tasks like pre-caching.\u003c/p\u003e\n"],["\u003cp\u003eEnabling warmup requests involves adding the \u003ccode\u003ewarmup\u003c/code\u003e element under the \u003ccode\u003einbound_services\u003c/code\u003e directive in your \u003ccode\u003eapp.yaml\u003c/code\u003e file, which activates the feature.\u003c/p\u003e\n"],["\u003cp\u003eWhile warmup requests aim to prevent loading requests, they are not guaranteed in all situations, such as when an instance is the very first one being started or if there is a sudden surge in traffic.\u003c/p\u003e\n"]]],[],null,["# Configuring Warmup Requests to Improve Performance\n\nYou can use warmup requests to reduce request and response latency during the\ntime when your app's code is being loaded to a newly created instance.\n\nApp Engine frequently needs to load your app's code into a fresh\ninstance. Loading an instance can happen in the following situations:\n\n- When you redeploy a version of your app.\n- When new instances are created due to the load from requests exceeding the capacity of the current set of running instances.\n- When maintenance and repairs of the underlying infrastructure or physical hardware occur.\n\nLoading your app's code to a new instance can result in [loading\nrequests](/appengine/docs/legacy/standard/go111/how-instances-are-managed#loading_requests).\nLoading requests can result in increased request latency for your users, but you\ncan avoid this latency using *warmup requests*. Warmup requests load your\napp's code into a new instance before any live requests reach that instance.\n\nIf warmup requests are enabled for your application, App Engine attempts\nto detect when your application needs a new instance and initiates a warmup\nrequest to initialize a new instance. However, these detection attempts do not\nwork in every case. As a result, you might encounter loading requests, even if\nwarmup requests are enabled in your app. For example, if your app is serving no\ntraffic, the first request to the app will always be a loading request, not a\nwarmup request.\n\nWarmup requests use instance hours like any other request to your\nApp Engine application. In most cases where warmup requests are enabled,\nyou won't notice an increase in instance hours because your application is\nsimply initializing in a warmup request instead of a loading request. Your\ninstance hour usage can increase if you decide to do more work, such as\npre-caching during a warmup request. If you set\n[`min_idle_instances`](/appengine/docs/legacy/standard/go111/config/appref#min_idle_instances)\nto greater than `0`, you might encounter warmup requests when those instances\nfirst start, but they will remain available after that time.\n\nEnabling warmup requests\n------------------------\n\nWarmup requests are used by the App Engine scheduler, which controls the\nauto scaling of instances based on user-supplied configuration. With warmup\nrequests enabled, App Engine issues `GET` requests to `/_ah/warmup`. You\ncan implement handlers for this request to perform application-specific tasks,\nsuch as pre-caching application data.\n\nThe scheduler starts up instances when it determines that more instances are\nneeded. Warmup requests may appear in\n[logs](/appengine/docs/legacy/standard/go111/writing-application-logs#viewing_logs)\neven if they are disabled because the scheduler uses them to start instances.\n\nNote that warmup requests are not guaranteed to be called. In some situations\nloading requests are sent instead: for example, if the instance is the first one\nbeing started up, or if there is a steep ramp-up in traffic. However, there\nwill be a \"best effort\" attempt to send requests to already warmed-up instances\nif warmup requests are enabled.\n\nTo enable warmup requests, add the `warmup` element under the\n[`inbound_services`](/appengine/docs/legacy/standard/go111/config/appref#inbound_services)\ndirective in your `app.yaml` file, for example: \n\n inbound_services:\n - warmup\n\n\u003cbr /\u003e\n\nCreating your handler\n---------------------\n\nCreate a handler that will process the requests that are sent to `/_ah/warmup`.\nYour handler should perform any warmup logic that is needed by your app.\n\n\n\n // Sample warmup demonstrates usage of the /_ah/warmup handler.\n package main\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"log\"\n \t\"net/http\"\n \t\"os\"\n \t\"time\"\n\n \t\"cloud.google.com/go/storage\"\n )\n\n var startupTime time.Time\n var client *storage.Client\n\n func main() {\n \t// Perform required setup steps for the application to function.\n \t// This assumes any returned error requires a new instance to be created.\n \tif err := setup(context.Background()); err != nil {\n \t\tlog.Fatalf(\"setup: %v\", err)\n \t}\n\n \t// Log when an appengine warmup request is used to create the new instance.\n \t// Warmup steps are taken in setup for consistency with \"cold start\" instances.\n \thttp.HandleFunc(\"/_ah/warmup\", func(w http.ResponseWriter, r *http.Request) {\n \t\tlog.Println(\"warmup done\")\n \t})\n \thttp.HandleFunc(\"/\", indexHandler)\n\n \tport := os.Getenv(\"PORT\")\n \tif port == \"\" {\n \t\tport = \"8080\"\n \t\tlog.Printf(\"Defaulting to port %s\", port)\n \t}\n\n \tlog.Printf(\"Listening on port %s\", port)\n \tif err := http.ListenAndServe(\":\"+port, nil); err != nil {\n \t\tlog.Fatal(err)\n \t}\n }\n\n // setup executes per-instance one-time warmup and initialization actions.\n func setup(ctx context.Context) error {\n \t// Store the startup time of the server.\n \tstartupTime = time.Now()\n\n \t// Initialize a Google Cloud Storage client.\n \tvar err error\n \tif client, err = storage.NewClient(ctx); err != nil {\n \t\treturn err\n \t}\n\n \treturn nil\n }\n\n // indexHandler responds to requests with our greeting.\n func indexHandler(w http.ResponseWriter, r *http.Request) {\n \tif r.URL.Path != \"/\" {\n \t\thttp.NotFound(w, r)\n \t\treturn\n \t}\n \tuptime := time.Since(startupTime).Seconds()\n \tfmt.Fprintf(w, \"Hello, World! Uptime: %.2fs\\n\", uptime)\n }\n\n\n\u003cbr /\u003e"]]