Советы по оптимизации
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
В этом документе описаны некоторые методы, которые можно использовать для повышения производительности вашего приложения. В некоторых случаях для иллюстрации представленных идей используются примеры других API или универсальных API. Однако те же концепции применимы и к Ad Exchange Buyer API.
Сжатие с помощью gzip
Простой и удобный способ уменьшить пропускную способность, необходимую для каждого запроса, — включить сжатие gzip. Хотя для распаковки результатов требуется дополнительное время процессора, компромисс с сетевыми затратами обычно делает это весьма выгодным.
Чтобы получить ответ в кодировке gzip, вы должны сделать две вещи: установить заголовок Accept-Encoding
и изменить свой пользовательский агент, чтобы он содержал строку gzip
. Вот пример правильно сформированных HTTP-заголовков для включения сжатия gzip:
Accept-Encoding: gzip
User-Agent: my program (gzip)
Работа с частичными ресурсами
Еще один способ повысить производительность вызовов API — запрашивать только ту часть данных, которая вас интересует. Это позволяет вашему приложению избежать передачи, анализа и хранения ненужных полей, поэтому оно может использовать ресурсы, включая сеть, процессор, и память более эффективна.
Частичный ответ
По умолчанию сервер отправляет обратно полное представление ресурса после обработки запросов. Для повышения производительности вы можете попросить сервер отправлять только те поля, которые вам действительно нужны, и вместо этого получать частичный ответ .
Чтобы запросить частичный ответ, используйте параметр запроса fields
, чтобы указать поля, которые вы хотите вернуть. Вы можете использовать этот параметр с любым запросом, который возвращает данные ответа.
Пример
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[null,null,["Последнее обновление: 2025-07-24 UTC."],[[["\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"]]