性能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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
错误。
如果您遇到该错误,请将请求拆分,并并行执行各个部分;这样可以避免长时间运行的请求失败,并且避免只能从头开始重新触发请求才能恢复的情况。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):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."]]