PHP 5 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、PHP 5 アプリケーションをデプロイできなくなります。既存の PHP 5 アプリケーションは、
非推奨になる日付以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの PHP に移行することをおすすめします。
アプリリソースの管理
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
App Engine は、アプリケーションのパフォーマンスとリソース使用率に関する使用状況レポートを生成します。以下に、リソースをより効率的に管理するための方法を示します。詳しくは料金のページをご覧ください。
使用状況レポートを表示する
アプリケーションのパフォーマンスを評価するときには、アプリケーションが実行されているインスタンス数や、アプリケーションによるリソースの消費状況を確認する必要があります。
ダッシュボードに使用状況レポートを表示
[インスタンス] ページを表示
以下のセクションで、リソースを管理する方法をいくつかご提案します。
動的インスタンス スケーリングの管理
レイテンシを短縮する
アプリケーションのレイテンシは、トラフィックの処理に必要なインスタンス数に影響します。レイテンシを短縮できれば、アプリケーションを提供するために使用するインスタンス数を減らすことができます。Cloud Trace は、レイテンシに関するデータを表示して、レイテンシを短縮するために見直すべき点を把握できる便利なツールです。
Cloud Trace を使用してレイテンシを表示した後、レイテンシを短縮するために次の方法をお試しください。
- アクセス頻度が高い共有データのキャッシュを大きくする: つまり、App Engine Memcache を使用することを意味します。また、アプリケーションのキャッシュ制御ヘッダーを設定すると、サーバーやブラウザによるデータのキャッシュ効率に大きな影響を与えることができます。数秒間キャッシュするだけでも、アプリケーションによるトラフィック処理の効率に影響を与えられます。
- App Engine Memcache をより効率的に使用する: 取得、設定、削除などの呼び出しを個々に行うのではなく、バッチで呼び出します。
- リクエストにバインドされない機能にはタスクを使用する: ユーザー対応リクエストのスコープ外で処理できる作業をアプリケーションで実行する場合は、その作業をタスクに入れてください。その作業が完了してレスポンスが返されるのを待つのではなく、その作業をタスクキューに送信することで、ユーザー側のレイテンシが大幅に短縮されます。タスクキューを使用すると、実行速度をより細かく管理できるようになり、負荷を軽減できます。
- Datastore モードの Firestore(Datastore)をより効率的に使用する: 詳細については、以下をご覧ください。
- 複数の URL 取得呼び出しを並列化する:
- 複数の URL 取得呼び出しを個々のユーザー対応リクエスト内で個別に処理するのではなく、バッチにまとめ、非同期 URL 取得を使用して 1 つのオフライン タスクで同時処理します。
- HTTP セッションの場合は、非同期書き込みを行う
app.yaml
構成ファイルに含まれるいくつかの設定を使用して、アプリの特定のバージョンのパフォーマンスとリソース負荷のトレードオフを調整できます。使用可能な自動スケーリング設定のリストについては、スケーリング要素をご覧ください。App Engine の新しいスケジューラの設定の動画を見ると、これらの設定の効果を確認できます。
タスクキュー設定を構成する
タスクキューのデフォルトの設定はパフォーマンスが高くなるように調整されています。これらのデフォルトの設定では、複数のタスクを同時にキューに入れると、高確率で新しいフロントエンド インスタンスが開始されます。インスタンス時間を節約するためにタスクキューを調整する方法の例を以下に紹介します。
- レイテンシがあまり重要でないタスクに X-AppEngine-FailFast ヘッダーを設定します。このヘッダーは、既存のインスタンスを使用できない場合はすぐにリクエストを止めるようにスケジューラに指示します。タスクキューは既存のインスタンスでリクエストを処理できるようになるまで、再試行とバックオフを実行します。ただし、X-AppEngine-FailFast が設定されたリクエストで既存のインスタンスがすべて使用されている場合は、そのヘッダーが設定されていないリクエストによって新しいインスタンスが開始されることがあるので注意してください。
可能であれば静的コンテンツを提供する
静的コンテンツの配信は、インスタンス時間を消費しない特殊な App Engine インフラストラクチャによって処理されます。
アプリケーション ストレージの管理
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 オペレーションには、データストア ID を割り当てるための呼び出しや、キーのみのクエリなどがあります。コストについては、料金ページをご覧ください。
その他のリソースの管理
エラー率を確認し、無効な呼び出しをしていないか確認することは常に重要です。場合によっては、そのような呼び出しを早期に検出することも可能です。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","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 UTC。"],[[["\u003cp\u003eApp Engine provides usage reports to help understand application performance and resource utilization, and you can view these reports through the provided dashboard and instances page links.\u003c/p\u003e\n"],["\u003cp\u003eReducing application latency, primarily through strategies like increasing caching, optimizing Memcache usage, and using tasks for non-request-bound work, can significantly decrease the number of instances required to serve traffic.\u003c/p\u003e\n"],["\u003cp\u003eConfiguring Task Queue settings, including using the X-AppEngine-FailFast header for non-latency-sensitive tasks, can help conserve instance hours by managing when new instances are started.\u003c/p\u003e\n"],["\u003cp\u003eOptimizing Datastore usage by removing unnecessary indexes, using keys-only queries, and employing batch \u003ccode\u003eget()\u003c/code\u003e calls can lower resource consumption and reduce latency.\u003c/p\u003e\n"],["\u003cp\u003eServing static content directly via App Engine's specialized infrastructure, rather than through dynamic instances, helps minimize the consumption of instance hours.\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/php/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- **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/php/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\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\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- 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\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"]]