Go 1.11 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Go 1.11 應用程式,即使貴機構先前使用機構政策重新啟用舊版執行階段的部署作業也一樣。現有的 Go 1.11 應用程式在
淘汰日期過後,仍會繼續執行並接收流量。建議您
遷移至最新支援的 Go 版本。
管理應用程式資源
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
App Engine 會產生應用程式效能和資源使用率的使用報告。以下列出一些相關的應用策略,協助您更有效率地管理資源。詳情請參閱定價頁面。
查看使用報告
評估應用程式效能時,您應檢查應用程式正在執行的執行個體數,以及應用程式耗用資源的方式。
查看資訊主頁使用報告
查看「Instances」(執行個體) 頁面
下面各節針對如何管理資源提供一些策略建議。
管理動態執行個體資源調度
減少延遲時間
應用程式延遲會影響處理流量所需的執行個體數量。降低延遲時間,就可以減少用來提供應用程式的執行個體數量。Cloud Trace 是一種非常有用的工具,可查看延遲的相關資料,以及瞭解減少延遲時間的可能變動。
使用 Cloud Trace 查看延遲後,請嘗試執行以下策略以減少延遲時間:
- 增加頻繁存取共用資料的快取:也就是使用 App Engine Memcache。另外,設定應用程式的快取控制標頭,也會對伺服器和瀏覽器快取資料的效率帶來重大影響。即使是幾秒鐘的快取作業,也會對應用程式提供流量的效率造成影響。
- 更有效率地使用 App Engine Memcache:對於 get、set、delete 等指令採用批次呼叫,而非發出一連串的個別呼叫。
- 使用非要求繫結功能工作:如果應用程式可以執行超出使用者要求範圍的作業,請將其加入工作!在傳回回應前,與其等待工作完成,不如將此工作傳送至工作佇列,這麼做可以大幅減少使用者經歷的延遲時間。工作佇列可讓您更完善地掌控執行率,並協助減少負載。
- 以更有效率的方式使用 Datastore 模式的 Firestore:詳情請見下文的說明。
- 同時執行多個網址擷取呼叫:
- 將多個網址擷取呼叫以批次處理,而不是在個別的使用者要求中分開處理,您可以透過非同步網址擷取以在離線工作中並行處理。
- 使用協程。
- 在 HTTP 工作階段中,以非同步方式寫入。
app.yaml
設定檔含有數種設定,可用於調整特定版本應用程式效能和資源負載之間的平衡。如需可用的自動調整資源配置設定清單,請參閱資源調度元素。請觀看 App Engine 新排程器設定影片,瞭解這些設定的效果。
注意:所有 Go 執行個體都會自動啟用並行要求。
指定工作佇列設定
工作佇列的預設設定已針對效能進行調整,如果使用這些預設值,當您將數個工作同時加入佇列時,很可能會導致系統啟動新的前端執行個體。以下針對如何調整工作佇列以節省執行個體時數提出一些建議:
- 針對不容易受到延遲影響的工作,設定 X-AppEngine-FailFast 標頭。如果現有的執行個體無法使用,這個標頭會指示排程器讓要求立即失效。工作佇列會一直重試和輪詢,直到現有的執行個體可用於提供要求為止。但請務必注意,如果設定了 X-AppEngine-FailFast 的要求佔用現有的執行個體,則未設定該標頭的要求仍會導致系統啟動新的執行個體。
儘可能提供靜態內容
提供靜態內容是由特殊的 App Engine 基礎架構處理,不會耗用執行個體時數。如果您需要設定自訂標頭,請使用 Blobstore API。實際提供 Blob 回應時不會耗用執行個體時數。
管理應用程式儲存空間
App Engine 會依據 Datastore 中的實體大小、Datastore 索引大小、工作佇列中的工作大小,以及儲存在 Blobstore 的資料數量來計算儲存空間費用。您可以執行以下作業以確保不會儲存非必要資料:
- 刪除應用程式不再需要的任何實體或 Blob。
- 依照以下「管理 Datastore 使用情形」一節,移除任何不必要的索引以減少索引儲存空間費用。
管理 Datastore 用量
App Engine 會計入在 Datastore 中執行的作業數量。以下幾項策略可降低 Datastore 的資源消耗量,以及減少 Datastore 要求的延遲時間:
- Google Cloud 主控台資料檢視器會顯示在本機 Datastore 中建立每個實體所需的寫入作業數,您可以透過這項資訊瞭解寫入每個實體的費用。如要瞭解如何解讀這項資料,請參閱「瞭解寫入費用」。
- 移除所有不必要的索引,以減少儲存空間和實體寫入費用。
如要查看目前提供給應用程式的索引,請參閱 Google Cloud 主控台搜尋頁面。
- 設計資料模型時,您或許可以使用這樣的方式來撰寫查詢,以避免使用自訂索引。如要進一步瞭解 App Engine 如何產生索引,請參閱查詢與索引說明文件。
- 盡可能以未編入索引的屬性取代已編入索引的屬性 (預設值),這樣可以在您加入實體時減少 Datastore 寫入作業數量。請注意,如果您日後決定確實需要查詢未編入索引的屬性,則不僅需要修改程式碼才能再次使用已編入索引的屬性,還必須對所有實體執行 map reduce 以重新加入。
- 我們已改進 App Engine 1.5.2 及 1.5.3 版中的 Datastore 查詢規劃工具,因此現在查詢需要的索引數可能比之前少。雖然您可能還是會為了維持效能而選擇保留某些自訂索引,但您可以刪除其他索引,以減少儲存空間和實體寫入費用。
- 請重新設定資料模型,以便利用鍵擷取代替查詢,不但成本較低,效率也更高。
- 如果可能,請使用僅限鍵查詢代替實體查詢。
- 如要減少延遲時間,請將多個實體
get()
替換成批次 get()
。
- 使用 Datastore 游標進行分頁而非位移。
- 透過 Async Datastore API 平行處理多個 Datastore 遠端程序呼叫 (RPC)。
注意:小型 Datastore 作業包括要求分配 Datastore ID 的呼叫或純索引鍵查詢。如要進一步瞭解費用,請參閱定價頁面。
管理其他資源
建議您務必檢查錯誤率,並查看是否發出任何無效呼叫。在某些情況下,也許可以及早找出這些呼叫。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-03 (世界標準時間)。
[[["容易理解","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-03 (世界標準時間)。"],[[["\u003cp\u003eApp Engine provides usage reports to help you understand your application's performance and resource consumption, with strategies available for more efficient resource management.\u003c/p\u003e\n"],["\u003cp\u003eReducing application latency, which can be achieved through techniques like increasing caching and using task queues, helps minimize the number of instances required to handle traffic.\u003c/p\u003e\n"],["\u003cp\u003eAdjusting the auto-scaling settings in the \u003ccode\u003eapp.yaml\u003c/code\u003e file allows for a trade-off between performance and resource load, with options outlined in the scaling elements section.\u003c/p\u003e\n"],["\u003cp\u003eOptimizing Task Queue settings, such as setting the X-AppEngine-FailFast header, can help conserve instance hours by managing how new instances are started.\u003c/p\u003e\n"],["\u003cp\u003eEfficient Datastore usage can be achieved by removing unnecessary indexes, replacing queries with key fetches, and utilizing batch operations and cursors.\u003c/p\u003e\n"]]],[],null,["# Managing App Resources\n\nApp Engine generates usage reports about your application's\nperformance and resources utilization. Listed below are potential strategies\nfor managing your resources more efficiently. For more information,\nsee the [pricing](/appengine/pricing) page.\n\nViewing usage reports\n---------------------\n\nWhen evaluating application performance, you should check the\nnumber of instances the application is running, and how the application\nconsumes resources.\n\n[View the dashboard usage reports](https://console.cloud.google.com/appengine)\n\n[View the Instances page](https://console.cloud.google.com/appengine/instances)\n\nThe following sections suggest some strategies for managing resources.\n\nManaging dynamic instance scaling\n---------------------------------\n\n### Decreasing latency\n\nApplication latency impacts the number of instances that are required to handle your\ntraffic. By decreasing latency, you can reduce the number of instances used to\nserve your application. [Cloud Trace](/trace) is a useful tool to view\ndata about latency and understand potential changes to decrease it.\n\nAfter using Cloud Trace to view your latency, try some of the following\nstrategies to reduce latency:\n\n- **Increase caching of frequently accessed shared data** - That's another way of saying - use App Engine Memcache. Also, setting your application's cache-control headers can have a significant impact on how efficiently your data is cached by servers and browsers. Even caching things for a few seconds can have an impact on how efficiently your application serves traffic.\n- **Use App Engine Memcache more efficiently** - Use batch calls for get, set, delete, etc instead of a series of individual calls.\n- **Use tasks for non-request bound functionality** - If your application performs work that can be done beyond the scope of a user-facing request, put it in a task! Sending this work to [Task Queue](/appengine/docs/legacy/standard/go111/taskqueue) instead of waiting for it to complete before returning a response can significantly reduce user-facing latency. Task Queue can then give you much more control over execution rates and help smooth out your load.\n- **Use Firestore in Datastore mode (Datastore) more efficiently** - See below for more detail.\n- **Execute multiple URL Fetch calls in parallel** :\n - Batch together multiple URL Fetch calls instead of handling them individually inside individual user-facing requests, and handle them in an offline task in parallel via async URL Fetch.\n - Use [goroutines](http://golang.org/doc/effective_go.html#concurrency).\n- **For HTTP sessions, write asynchronously**.\n\n### Change auto-scaling performance settings\n\nThe `app.yaml`\nconfiguration file contains several settings you can use to\nadjust the trade-off between performance and resource load for a specific version\nof your app.\nFor a list of the available auto-scaling settings, see\n[scaling elements](/appengine/docs/legacy/standard/go111/config/appref#scaling_elements).\nWatch the App Engine [New Scheduler Settings](https://www.youtube.com/watch?v=eUXUY7QFfAI)\nvideo to see the effects of these settings.\n**Note:** All Go instances have concurrent requests enabled automatically.\n\n### Configuring Task Queue settings\n\nThe default settings for Task Queue are tuned for performance. With these\ndefaults, when you put several tasks into a queue simultaneously, they will\nlikely cause new Frontend Instances to start. Here are some suggestions for\nhow to tune Task Queue to conserve Instance Hours:\n\n- Set the X-AppEngine-FailFast header on tasks that are not latency sensitive. This header instructs the scheduler to immediately fail the request if an existing instance is not available. Task Queue will retry and back-off until an existing instance becomes available to service the request. However, it is important to note that when requests with X-AppEngine-FailFast set occupy existing instances, requests without that header set may still cause new instances to be started.\n\n### Serve static content where possible\n\nStatic content serving\n\n\nis handled by specialized App Engine infrastructure, which does not consume\nInstance Hours.\n\n\nIf you need to set custom headers, use the\n[Blobstore API](/appengine/docs/legacy/standard/go111/blobstore). The actual serving of\nthe Blob response does not consume Instance Hours.\n\n\nManaging application storage\n----------------------------\n\nApp Engine calculates storage costs based on the size of entities in the\nDatastore, the size of Datastore indexes, the size\nof tasks in the task queue, and the amount of data stored in Blobstore. Here are\nsome things you can do to make sure you don't store more data than necessary:\n\n- Delete any entities or blobs your application no longer needs.\n- Remove any unnecessary indexes, as discussed in the *Managing Datastore\n Usage* section below, to reduce index storage costs.\n\nManaging Datastore usage\n------------------------\n\nApp Engine accounts for the number of operations performed in\nDatastore. Here are a few strategies that can result in reduced\nDatastore resource consumption, as well as lower latency for\nrequests to Datastore:\n\n- The Google Cloud console dataviewer displays the number of write ops that were required to create every entity in your local Datastore. You can use this information to understand the cost of writing each entity. See [Understanding Write Costs](/appengine/docs/legacy/standard/java/datastore/entities#Understanding_Write_Costs) for information on how to interpret this data.\n- Remove any unnecessary indexes, which will reduce storage and entity write costs. You can see what indexes are currently serving for your application in the [Google Cloud console Search page](https://console.cloud.google.com/project/_/appengine/search).\n- When designing your data model, you might be able to write your queries in such a way so as to avoid custom indexes altogether. Read [Queries and Indexes](/appengine/docs/legacy/standard/python/datastore/queries) documentation for more information on how App Engine generates indexes.\n- Whenever possible, replace indexed properties (which are the default) with unindexed properties ( ), which reduces the number of Datastore write operations when you put an entity. Caution, if you later decide that you do need to be able to query on the unindexed property, you will need to not only modify your code to again use indexed properties, but you will have to run a [map reduce](https://github.com/googlecloudplatform/appengine-mapreduce) over all entities to reput them.\n- Due to Datastore query planner improvements in App Engine 1.5.2 and 1.5.3 releases, your queries may now require fewer indexes than they did previously. While you may still choose to keep certain custom indexes for performance reasons, you may be able to delete others, reducing storage and entity write costs.\n- Reconfigure your data model so that you can [replace queries with fetch by\n key](/appengine/docs/legacy/standard/go/datastore/reference#Get) which is cheaper and more efficient.\n- Use keys-only queries instead of entity queries when possible.\n- To decrease latency, replace multiple entity `get()`s with a batch `get()`.\n- Use Datastore cursors for pagination rather than offset.\n- Parallelize multiple Datastore RPCs via the [async datastore API](http://golang.org/doc/effective_go.html#concurrency).\n\n**Note:** Small Datastore operations include calls to allocate\nDatastore ids or keys-only queries. See the\n[pricing](/appengine/pricing#cost_resource) page for more information on costs.\n\nManaging other resources\n------------------------\n\nIt's always a good idea to make sure you are checking your error rates and looking out for any invalid calls you might be making. In some cases it might be possible to catch those calls early.\n\n\u003cbr /\u003e"]]