效能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Perl 適用的用戶端程式庫可簡化與 Google Ads API 的互動,您只需進行最少的設定。不過,效能高度取決於程式庫的使用和整合方式。
這些最佳做法大多適用於所有語言。本指南將介紹 Perl 專屬的項目。
剖析應用程式
分析應用程式的 CPU 和記憶體用量,找出效能瓶頸。Devel::NYTProf 是一個功能強大的 Perl 原始碼剖析器,值得您深入瞭解。
Perl 版本
建議定期升級至較新的 Perl 版本,因為新版本通常整體效能較佳。如要查看最新 Perl 版本,以及這個頁面中程式庫的最低必要版本,請參閱這裡。
記錄
大量記錄可能會導致執行時間大幅增加,並消耗大量記憶體。建議您將任何正式版程式碼的記錄層級設為 WARN
。
如要進一步瞭解摘要和詳細記錄器的設定,請參閱記錄指南。
Search 或 SearchStream 方法
Google Ads API 提供兩種主要方法來擷取物件:Search
(使用分頁) 和 SearchStream
(使用串流)。SearchStream
方法的效能優於 Search
方法,但在某些情況下,Search
方法可能較為合適。
如要進一步瞭解這兩種方法,請參閱這篇文章。
HTTP 逾時
Perl 用戶端程式庫提供介面,可在用戶端層級設定 HTTP 超時:
my $api_client = Google::Ads::GoogleAds::GoogleAdsClient->new({
# Set HTTP timeout to 5 minutes.
http_timeout => 300
});
預設值是根據 Constants.pm 中的 DEFAULT_HTTP_TIMEOUT
設定而定。如果需要強制縮短 API 呼叫時間上限,請設定較低的值。
您可以將逾時時間設為 2 小時以上,但對於執行時間極長的要求,API 仍可能逾時並傳回 DEADLINE_EXCEEDED
錯誤。如果遇到這類錯誤,請將要求分割成多個區塊,並平行執行這些區塊;這樣可避免長時間執行的要求失敗,且只能從頭再次觸發要求才能復原的情況。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[[["\u003cp\u003eThe Google Ads API client library for Perl simplifies interactions, but performance depends on usage and integration.\u003c/p\u003e\n"],["\u003cp\u003eRegularly update your Perl version and use the \u003ccode\u003eSearchStream\u003c/code\u003e method for enhanced performance.\u003c/p\u003e\n"],["\u003cp\u003eMinimize extensive logging and set appropriate HTTP timeouts to optimize API calls.\u003c/p\u003e\n"],["\u003cp\u003eProfile your application with tools like Devel::NYTProf to pinpoint and address performance bottlenecks.\u003c/p\u003e\n"],["\u003cp\u003eSplit large, long-running requests into smaller, parallel chunks to prevent \u003ccode\u003eDEADLINE_EXCEEDED\u003c/code\u003e errors.\u003c/p\u003e\n"]]],[],null,["# Performance\n\nThe client library for Perl eases interactions with the Google Ads API, with minimal\nconfiguration on your part. However, performance highly depends on how the\nlibrary is used and integrated.\n\nMost of [these best practices](/google-ads/api/docs/best-practices/overview)\nare applicable to all languages. This guide goes through the ones that are\nspecific to Perl.\n\nProfiling your application\n--------------------------\n\nProfile your application both for CPU and memory usage to identify performance\nbottlenecks. [Devel::NYTProf](//metacpan.org/pod/Devel::NYTProf) is a powerful\nfeature-rich Perl source code profiler that you can explore.\n\nPerl version\n------------\n\nIt is a good practice to regularly upgrade to a newer Perl version as it usually\ncomes with better overall performance. See [here](//www.cpan.org/src/) for the\nlatest Perl version, and the minimum required version for the library in this\n[page](https://github.com/googleads/google-ads-perl/blob/HEAD/README.md#requirements).\n\nLogging\n-------\n\nExtensive logging can incur significant execution time penalties and memory\nconsumption. We recommend setting the logging level to `WARN` for any code in\nproduction.\n\nSee the [Logging guide](/google-ads/api/docs/client-libs/perl/logging) for more\ndetails about the configuration of summary and detail loggers.\n\nSearch or SearchStream method\n-----------------------------\n\nGoogle Ads API provides two main methods to retrieve objects --\n[`Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) (which uses pagination) and\n[`SearchStream`](/google-ads/api/reference/rpc/v21/GoogleAdsService/SearchStream) (which uses streaming).\n`SearchStream` provides better performance over `Search` method, but there might\nbe certain scenarios where `Search` method might be preferred.\n\nYou can learn more about the two methods [here](/google-ads/api/docs/reporting/streaming).\n\nHTTP timeout\n------------\n\nThe Perl client library provides a surface for setting HTTP timeouts on the client\nlevel: \n\n my $api_client = Google::Ads::GoogleAds::GoogleAdsClient-\u003enew({\n # Set HTTP timeout to 5 minutes.\n http_timeout =\u003e 300\n });\n\nThe default value is set based on the `DEFAULT_HTTP_TIMEOUT` setting in\n[Constants.pm](https://github.com/googleads/google-ads-perl/blob/main/lib/Google/Ads/GoogleAds/Constants.pm).\n[Set a lower value](/google-ads/api/samples/set-custom-client-timeouts#perl) if you\nneed to enforce a shorter limit on the maximum time for an API call.\n\nYou can set the timeout to 2 hours or more, but the API may still time out\nextremely long-running requests and return a\n[`DEADLINE_EXCEEDED`](/google-ads/api/reference/rpc/v21/InternalErrorEnum.InternalError) error.\nIf you encounter that error, split the request up and execute the chunks in\nparallel; this avoids the situation where a long running request fails and\nthe only way to recover is to trigger the request again from the start."]]