最佳实践和限制
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用 BatchJobService
时,请考虑以下准则。
提高吞吐量
最好是少量的大型作业,而不是许多小型作业。
按操作类型对上传的操作进行排序。例如,如果您的作业包含用于添加广告系列、广告组和广告组定位条件的各项操作,请在上传时对这些操作进行排序,以便先执行所有广告系列操作,然后执行所有广告组操作,最后执行所有广告组定位条件操作。
在同一类型的操作中,按父资源对操作进行分组可以提高性能。例如,如果您有一系列AdGroupCriterionOperation
对象,按广告组对操作进行分组可能比混合影响不同广告组中广告组条件的各种操作更高效。
避免并发问题
以最佳方式检索结果
其他使用指南
限制
每个 BatchJob
最多支持 100 万次操作。
每个账号最多可同时有 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);
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):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);"]]