Google Analytics API 会限制请求吗?

Does the Google Analytics API throttle requests?

Google Analytics API 是否限制请求?

我们有一个批处理脚本,我刚刚从 API 的 v2 移动到 v3,并且请求在第一位(50 个左右的查询)中非常顺利,然后他们开始花费 4s 或所以每个。这是 Google 限制我们吗?

Google 的 Analytics API 根据其文档确实有速率限制:https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors

但是它们不应导致请求延迟,而应该返回请求并响应:403 userRateLimitExceeded

错误描述: 表示已超过用户速率限制。每个 IP 地址的最大速率限制为 10 qps。 Google Developers Console 中设置的默认值是每个 IP 地址 1 qps。您可以在 Google Developers Console 中将此限制增加到最大 10 qps。

Google 推荐的操作步骤: 使用指数退避重试。您需要放慢发送请求的速度。

虽然 Matthew 是正确的,但我为您提供了另一种可能性。 Google analytics API 在某种程度上兑现了您的请求。让我试着解释一下。

我有一个客户/站点,我从中请求数据。在测试时我注意到了一些奇怪的事情。

  1. 前一百万行结果将在可接受的时间内返回。
  2. 在一百万行之后,事情开始变慢,我们看到结果 return 的时间是原来的 5 分钟的 5 倍,我们等待 20 分钟或更长时间才能看到结果 return .

示例:

Request URL : https://www.googleapis.com/analytics/v3/data/ga?ids=ga:34896748&dimensions=ga:date,ga:sourceMedium,ga:country,ga:networkDomain,ga:pagePath,ga:exitPagePath,ga:landingPagePath&metrics=ga:entrances,ga:pageviews,ga:exits,ga:bounces,ga:timeOnPage,ga:uniquePageviews&filters=ga:userType%3D%3DReturning+Visitor;ga:deviceCategory%3D%3Ddesktop&start-date=2014-05-12&end-date=2014-05-22&start-index=236001&max-results=2000&oauth_token={OauthToken} Request Time (seconds:milliseconds): :0:484

Request URL : https://www.googleapis.com/analytics/v3/data/ga?ids=ga:34896748&dimensions=ga:date,ga:sourceMedium,ga:country,ga:networkDomain,ga:pagePath,ga:exitPagePath,ga:landingPagePath&metrics=ga:entrances,ga:pageviews,ga:exits,ga:bounces,ga:timeOnPage,ga:uniquePageviews&filters=ga:userType%3D%3DReturning+Visitor;ga:deviceCategory%3D%3Ddesktop&start-date=2014-05-12&end-date=2014-05-22&start-index=238001&max-results=2000&oauth_token={OauthToken} Request Time (seconds:milliseconds): :7:968

我做了很多测试来停止和启动我的应用程序。我不明白为什么数据一开始这么快,后来就慢了。

现在我在 Google 分析开发团队有一些联系人,他们是 API 的负责人。所以我制作了一个不错的测试应用程序,记录了一些显示我的问题的结果并将其发送给他们。随着问题 Are you throttling me?

他们也一头雾水,告诉我API没有油门。 Matthew 谈到了防洪限制。我的开发人员联系人将其转发给负责流量的人员。

快进几周。它接缝当我们请求一堆数据时 Google 为我们兑现数据。它保存在服务器上以防我们再次请求它。通过重新启动我的应用程序,我正在访问已兑现的数据,它 return 很快。当我让应用程序 运行 更长的时间时,我会突然到达非兑现数据并且他们需要更长的时间才能 return 请求。

我问数据提现多久,回答没有规定时间。所以我不认为你被节流了。我认为您最初的快速请求是兑现数据,而较慢的请求是非兑现数据。

从 google 回复的电子邮件:

Hi Linda,

I talked to the engineers and they had a look. The response was basically that they thinks it's because of caching. The response is below. If you could do some additional queries to confirm the behavior it might be helpful. However, what they need to determine is if it's because you are querying and hitting cached results (because you've already asked for that data). Anyway, take a look at the comments below and let me know if you have additional questions or results that you can share.

Summary from talking to engineer: "Items not already in our cache will exhibit a slower retrieval processing time than items already present in the cache. The first query loads the response into our cache and typical query times without using the cache is about 7 seconds and with using the cache is a few milliseconds. We can also confirm that you are not hitting any rate limits on our end, as far as we can tell.

To confirm if this is indeed what's happening in your case, you might want to rerun verified slow queries a second time to see if the next query speeds up considerably (this could be what you're seeing when you say you paste the request URL into a browser and results return instantly)."

-- IMBA Google Analytics API Developer --