效果提示
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档介绍了可用来提高应用性能的方法和技巧。在某些情况下,我们会采用其他 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
请求参数来指定您希望返回的字段。对于返回响应数据的任何请求,您都可以使用此参数。
示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):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"]]