效能提升秘訣
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本文說明提升應用程式成效的幾個技巧。在某些情況下,我們會使用其他 API 或通用 API 的範例來說明這些技巧背後的概念。不過,同樣的概念也適用於 Ad Exchange Buyer API。
使用 gzip 壓縮
要減少每個要求占用的頻寬,最簡單的方法就是使用 gzip 壓縮檔。雖然此方法需要額外的 CPU 作業時間解壓縮,但相對可省下可觀的網路成本。
如果要接收以 gzip 編碼的回應,您必須執行下列兩項操作:設定 Accept-Encoding
標頭,並修改您的使用者代理程式來加入字串 gzip
。以下是一個啟用 gzip 壓縮的正確 HTTP 標頭格式範例:
Accept-Encoding: gzip
User-Agent: my program (gzip)
使用部分資源
另一種提高 API 呼叫效能的方式,就是只要求您想要的部分資料。這麼做可避免讓您的應用程式傳輸、剖析及儲存不需要的欄位,進而更有效地使用網路、CPU 及記憶體等資源。
部分回應
根據預設,伺服器會在處理要求後傳回完整的資源表示法。為改善成效,您可以要求伺服器只傳送您真正需要的欄位,並改為取得「部分回應」。
如果要請求部分回應,請使用 fields
要求參數來指定您想要傳回的欄位。您可以將此參數搭配任何會傳回回應資料的要求使用。
範例
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eEnabling gzip compression reduces bandwidth usage by compressing data, which often outweighs the cost of extra CPU time required for decompression.\u003c/p\u003e\n"],["\u003cp\u003eTo receive a gzip-encoded response, set the \u003ccode\u003eAccept-Encoding\u003c/code\u003e header to \u003ccode\u003egzip\u003c/code\u003e and include \u003ccode\u003egzip\u003c/code\u003e in your user agent string.\u003c/p\u003e\n"],["\u003cp\u003eRequesting partial resources, by only retrieving the data fields you need, improves application performance by conserving resources such as network, CPU, and memory.\u003c/p\u003e\n"],["\u003cp\u003ePartial responses are achieved by using the \u003ccode\u003efields\u003c/code\u003e request parameter to specify which fields you want returned from the server, instead of receiving the full resource representation.\u003c/p\u003e\n"]]],["To enhance application performance, enable gzip compression by setting the `Accept-Encoding: gzip` header and including `gzip` in the `User-Agent`. Additionally, request only necessary data by utilizing partial responses. Employ the `fields` request parameter to specify desired fields, thereby reducing data transfer, parsing, and storage overhead, optimizing network, CPU, and memory usage. These techniques can be used for the Ad Exchange Buyer API.\n"],null,["# Performance Tips\n\nThis document covers some techniques you can use to improve the performance of your application. In some cases, examples from other APIs or generic APIs are used to illustrate the ideas presented. However, the same concepts are applicable to the Ad Exchange Buyer API.\n\nCompression using gzip\n----------------------\n\nAn easy and convenient way to reduce the bandwidth needed for each request is to enable gzip compression. Although this requires additional CPU time to uncompress the results, the trade-off with network costs usually makes it very worthwhile.\n\nIn order to receive a gzip-encoded response you must do two things: Set an `Accept-Encoding` header, and modify your user agent to contain the string `gzip`. Here is an example of properly formed HTTP headers for enabling gzip compression: \n\n```perl6\nAccept-Encoding: gzip\nUser-Agent: my program (gzip)\n```\n\nWorking with partial resources\n------------------------------\n\nAnother way to improve the performance of your API calls is by requesting only the portion of the data that you're interested in. This lets your application avoid transferring, parsing, and storing unneeded fields, so it can use resources including network, CPU, and memory more efficiently.\n\n### Partial response\n\nBy default, the server sends back the full representation of a resource after processing requests. For better performance, you can ask the server to send only the fields you really need and get a *partial response* instead.\n\nTo request a partial response, use the `fields` request parameter to specify the fields you want returned. You can use this parameter with any request that returns response data.\n\n#### Example"]]