أفضل الممارسات والقيود
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يُرجى مراعاة الإرشادات التالية عند استخدام BatchJobService
.
تحسين سرعة نقل البيانات
يُفضّل أن تكون المهام الأكبر أقل من المهام الأصغر.
ترتيب العمليات التي تم تحميلها حسب نوع العملية على سبيل المثال، إذا كانت مهمتك تتضمّن عمليات لإضافة حملات ومجموعات إعلانية ومعايير مجموعات إعلانية، رتِّب العمليات في عملية التحميل بحيث تكون جميع عمليات الحملة أولاً، تليها جميع عمليات المجموعة الإعلانية، وأخيرًا جميع عمليات معايير المجموعة الإعلانية.
في العمليات من النوع نفسه، يمكن تحسين الأداء من خلال تجميعها حسب المورد الرئيسي. على سبيل المثال، إذا كان لديك سلسلة من
AdGroupCriterionOperation
الكائنات، قد يكون من الأفضل تجميع العمليات حسب المجموعة الإعلانية، بدلاً من دمج العمليات التي تؤثّر في معايير المجموعة الإعلانية في مجموعات إعلانية مختلفة.
تجنُّب مشاكل التزامن
عند إرسال مهام متزامنة متعددة للحساب نفسه، حاوِل تقليل احتمالية أن تعمل المهام على الكائنات نفسها في الوقت نفسه، مع الحفاظ على أحجام المهام الكبيرة. عندما يكون هناك العديد من المهام غير المكتملة التي تحمل الحالة
RUNNING
،
تحاول هذه المهام تعديل المجموعة نفسها من العناصر، ما قد يؤدي إلى
حالات شبيهة بالتعطّل التام ينتج عنها تباطؤ شديد وحتى تعذّر إكمال المهام.
لا ترسِل عمليات متعددة تعدّل الكائن نفسه في مهمة واحدة، لأنّ النتيجة قد تكون غير متوقعة.
استرداد النتائج على النحو الأمثل
لا تطلب حالة المهمة بشكل متكرر جدًا، وإلا ستخاطر بمواجهة أخطاء الحدّ الأقصى لمعدّل الطلبات.
لا تستردّ أكثر من 1,000 نتيجة في كل صفحة. قد يعرض الخادم عددًا أقل من ذلك بسبب الحمولة أو عوامل أخرى.
سيكون ترتيب النتائج هو نفسه ترتيب التحميل.
إرشادات إضافية حول الاستخدام
يمكنك ضبط حد أعلى لمدة السماح بتشغيل مهمة مجمّعة قبل إلغائها. عند إنشاء مهمة معالجة مجمّعة جديدة، اضبط الحقل
metadata.execution_limit_seconds
على الحدّ الزمني المفضّل لديك، بالثواني. لا يوجد حد زمني تلقائي إذا لم يتم ضبط metadata.execution_limit_seconds
.
ننصحك بعدم إضافة أكثر من 1,000 عملية لكل AddBatchJobOperationsRequest
واستخدام sequence_token
لتحميل بقية العمليات إلى مهمة التحميل نفسها. استنادًا إلى محتوى العمليات، قد يؤدي عدد كبير جدًا من العمليات في AddBatchJobOperationsRequest
واحد إلى حدوث خطأ REQUEST_TOO_LARGE
. يمكنك معالجة هذا الخطأ عن طريق تقليل عدد العمليات وإعادة محاولة تنفيذ AddBatchJobOperationsRequest
.
القيود
يمكن لكل BatchJob
تنفيذ ما يصل إلى مليون عملية.
يمكن أن يضمّ كل حساب ما يصل إلى 100 مهمة نشطة أو في انتظار المراجعة في الوقت نفسه.
تتم تلقائيًا إزالة المهام المعلقة التي مرّ عليها أكثر من 7 أيام.
يبلغ الحد الأقصى لحجم كل AddBatchJobOperationsRequest
10,484,504 بايت. إذا تجاوزت هذا الحد، ستتلقّى INTERNAL_ERROR
. يمكنك تحديد حجم الطلب قبل إرساله واتّخاذ الإجراء المناسب إذا كان كبيرًا جدًا.
Java
static final int MAX_REQUEST_BYTES = 10_484_504;
... (code to get the request object)
int sizeInBytes = request.getSerializedSize();
Python
from google.ads.googleads.client import GoogleAdsClient
MAX_REQUEST_BYTES = 10484504
... (code to get the request object)
size_in_bytes = request._pb.ByteSize()
Ruby
require 'google/ads/google_ads'
MAX_REQUEST_BYTES = 10484504
... (code to get the request object)
size_in_bytes = request.to_proto.bytesize
PHP
use Google\Ads\GoogleAds\V16\Resources\Campaign;
const MAX_REQUEST_BYTES = 10484504;
... (code to get the request object)
$size_in_bytes = $campaign->byteSize() . PHP_EOL;
NET.
using Google.Protobuf;
const int MAX_REQUEST_BYTES = 10484504;
... (code to get the request object)
int sizeInBytes = request.ToByteArray().Length;
Perl
use Devel::Size qw(total_size);
use constant MAX_REQUEST_BYTES => 10484504;
... (code to get the request object)
my $size_in_bytes = total_size($request);
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eTo improve throughput when using BatchJobService, submit fewer, larger jobs and order operations by type and parent resource to enhance efficiency.\u003c/p\u003e\n"],["\u003cp\u003eWhen running concurrent jobs, minimize the likelihood of them operating on the same objects simultaneously to avoid potential deadlock-like conditions and job failures.\u003c/p\u003e\n"],["\u003cp\u003eFor optimal results retrieval, avoid excessive job status polling and retrieve results in batches of 1,000 or less to prevent rate limit errors and ensure efficient data handling.\u003c/p\u003e\n"],["\u003cp\u003eBatchJobService allows setting an execution time limit and recommends a maximum of 1,000 operations per request to avoid exceeding size limitations and potential errors.\u003c/p\u003e\n"],["\u003cp\u003eEach BatchJob is subject to limitations, including a maximum of one million operations, 100 active or pending jobs per account, a 7-day lifespan for pending jobs, and a request size limit of 10,484,504 bytes.\u003c/p\u003e\n"]]],[],null,["# Best Practices and Limitations\n\nConsider these guidelines when using [`BatchJobService`](/google-ads/api/reference/rpc/v21/BatchJobService).\n\nImprove throughput\n------------------\n\n- Fewer larger jobs is preferred over many smaller jobs.\n\n- Order uploaded operations by operation type. For example, if your job\n contains operations to add campaigns, ad groups, and ad group criteria,\n order the operations in your upload so that all of the [campaign\n operations](/google-ads/api/reference/rpc/v21/CampaignOperation) are first, followed by all of\n the [ad group operations](/google-ads/api/reference/rpc/v21/AdGroupOperation), and finally all\n [ad group criterion operations](/google-ads/api/reference/rpc/v21/AdGroupCriterionOperation).\n\n- Within operations of the same type, it can improve performance to group them\n by parent resource. For example, if you have a series of\n `AdGroupCriterionOperation` objects, it can be more efficient to group\n operations by ad group, rather than intermixing operations that affect ad\n group criteria in different ad groups.\n\nAvoid concurrency issues\n------------------------\n\n- When submitting multiple concurrent jobs for the same account, try to reduce\n the likelihood of jobs operating on the same objects at the same time, while\n maintaining large job sizes. Many unfinished jobs, which have the status of\n [`RUNNING`](/google-ads/api/reference/rpc/v21/BatchJobStatusEnum.BatchJobStatus#running),\n try to mutate the same set of objects, which can lead to deadlock-like\n conditions resulting in severe slow-down and even job failures.\n\n- Don't submit multiple operations that mutate the same object in the same\n job, as the result can be unpredictable.\n\nRetrieve results optimally\n--------------------------\n\n- Don't poll the job status too frequently or you risk hitting rate limit\n errors.\n\n- Don't retrieve more than 1,000 results per page. The server could return\n fewer than that due to load or other factors.\n\n- The results order will be the same as the upload order.\n\nAdditional usage guidance\n-------------------------\n\n- You can set an upper bound for how long a batch job is allowed to run before\n being cancelled. When creating a new batch job, set the\n [`metadata.execution_limit_seconds`](/google-ads/api/reference/rpc/v21/BatchJob.BatchJobMetadata#execution_limit_seconds)\n field to your preferred time limit, in seconds. There is no default time\n limit if `metadata.execution_limit_seconds` is not set.\n\n- It is recommended to add no more than 1,000 operations per\n [`AddBatchJobOperationsRequest`](/google-ads/api/reference/rpc/v21/BatchJobService/AddBatchJobOperations)\n and use the\n [`sequence_token`](/google-ads/api/reference/rpc/v21/AddBatchJobOperationsRequest#sequence_token)\n to upload the rest of the operations to the same job. Depending on the\n content of the operations, too many operations in a single\n `AddBatchJobOperationsRequest` could cause a [`REQUEST_TOO_LARGE`](/google-ads/api/reference/rpc/v21/DatabaseErrorEnum.DatabaseError#request_too_large) error. You\n can handle this error by reducing the number of operations and retrying the\n `AddBatchJobOperationsRequest`.\n\nLimitations\n-----------\n\n- Each [`BatchJob`](/google-ads/api/reference/rpc/v21/BatchJob) supports up to one million\n operations.\n\n- Each account can have up to 100 active or pending jobs at the same time.\n\n- Pending jobs older than 7 days are automatically removed.\n\n- Each [`AddBatchJobOperationsRequest`](/google-ads/api/reference/rpc/v21/BatchJobService/AddBatchJobOperations)\n has a maximum size of 10,484,504 bytes. If you exceed this, you will receive\n an `INTERNAL_ERROR`. You can determine the size of the request before\n submitting and take appropriate action if it is too large.\n\n ### Java\n\n\n static final int MAX_REQUEST_BYTES = 10_484_504;\n\n ... (code to get the request object)\n\n int sizeInBytes = request.getSerializedSize();\n\n ### Python\n\n\n from google.ads.googleads.client import GoogleAdsClient\n\n MAX_REQUEST_BYTES = 10484504\n\n ... (code to get the request object)\n\n size_in_bytes = request._pb.ByteSize()\n\n ### Ruby\n\n\n require 'google/ads/google_ads'\n\n MAX_REQUEST_BYTES = 10484504\n\n ... (code to get the request object)\n\n size_in_bytes = request.to_proto.bytesize\n\n ### PHP\n\n\n use Google\\Ads\\GoogleAds\\V16\\Resources\\Campaign;\n\n const MAX_REQUEST_BYTES = 10484504;\n\n ... (code to get the request object)\n\n $size_in_bytes = $campaign-\u003ebyteSize() . PHP_EOL;\n\n ### .NET\n\n\n using Google.Protobuf;\n const int MAX_REQUEST_BYTES = 10484504;\n\n ... (code to get the request object)\n\n int sizeInBytes = request.ToByteArray().Length;\n\n ### Perl\n\n\n use Devel::Size qw(total_size);\n use constant MAX_REQUEST_BYTES =\u003e 10484504;\n\n ... (code to get the request object)\n\n my $size_in_bytes = total_size($request);"]]