نصائح حول الأداء
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
ويتناول هذا المستند بعض الأساليب التي يمكنك استخدامها لتحسين أداء تطبيقك. في بعض الحالات، يتم استخدام أمثلة من واجهات برمجة تطبيقات أخرى أو واجهات برمجة تطبيقات عامة لتوضيح الأفكار المعروضة. ومع ذلك، تنطبق المفاهيم نفسها على واجهة برمجة تطبيقات Ad Exchange Purchases API.
الضغط باستخدام gzip
وهناك طريقة سهلة وملائمة لتقليل معدل نقل البيانات اللازم لكل طلب، وهي تمكين الضغط بتنسيق gzip. وعلى الرغم من أن هذا يتطلب وقتًا إضافيًا لوحدة المعالجة المركزية (CPU) لفك ضغط النتائج، فإن المقايضة مع تكاليف الشبكة عادةً ما تجعل الأمر مفيدًا للغاية.
لتلقي استجابة بترميز gzip، عليك عمل شيئين: ضبط العنوان Accept-Encoding
وتعديل وكيل المستخدم بحيث يتضمن السلسلة gzip
. في ما يلي مثال على عناوين HTTP تم تشكيلها بشكل صحيح لتفعيل ضغط gzip:
Accept-Encoding: gzip
User-Agent: my program (gzip)
استخدام الموارد الجزئية
هناك طريقة أخرى لتحسين أداء طلبات البيانات من واجهة برمجة التطبيقات، وهي عن طريق طلب جزء البيانات الذي يهمّك فقط. ويتيح ذلك لتطبيقك تجنب نقل الحقول غير الضرورية وتحليلها وتخزينها، حتى يتمكن من استخدام الموارد بشكل أكثر فعالية، بما في ذلك الشبكة ووحدة المعالجة المركزية (CPU) والذاكرة.
ردّ جزئي
يرسل الخادم تلقائيًا التمثيل الكامل للمورد بعد معالجة الطلبات. للحصول على أداء أفضل، يمكنك أن تطلب من الخادم إرسال الحقول التي تحتاجها فقط والحصول على ردّ جزئي بدلاً من ذلك.
لطلب استجابة جزئية، استخدِم مَعلمة طلب fields
لتحديد الحقول التي تريد عرضها. يمكنك استخدام هذه المعلمة مع أي طلب يعرض بيانات الاستجابة.
مثال
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 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"]]