了解Gmail API配额 [英] Understanding Gmail api quotas

查看:191
本文介绍了了解Gmail API配额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读这里的gmail api配额说明( https://开发人员.google.com / gmail / api / v1 / reference / quota ),但我们仍然无法理解是什么导致我们超过了限制。

问题1:
每位用户配额中的用户是什么?我不确定用户是个人gmail用户还是使用gmail api的服务客户端。



问题2:
我们已经看到以下内容错误几次,但没有看到我们遇到的任何明显限制。

 error:{
errors:[
{
domain :usageLimits,
reason:rateLimitExceeded,
message:超出限额
}
],
code:429 ,
message:超过限额
}

低于250个单位/秒和25,000个单位/ 100个。我们只使用history.list和message.get调用不发送或修改。

是否还有其他一些我缺少的配额?

解决方案


  1. 用户配额基于您正在访问的帐户。所以这将是GMail帐户。有时,您可以通过随机发送 quotaUser 来欺骗它,但是并不总是有效谷歌也使用你的IP地址来追踪我怀疑的配额。

  2. 用户速率限制是你要快速进行的防洪保护。




每用户速率限制每用户每秒250个配额单位,移动
平均值(允许短连发)



超出速率限制将导致HTTP 403或HTTP 429太多
请求响应,您的应用应通过重试
指数回退。


谷歌计算并不完美,您可能会发送更多或更少的数据,并且仍然达到此配额。只是实施指数退避。
$ b 指数回退



执行简单指数回退的流程如下:
$ b


  1. 发出API请求。

  2. 接收HTTP 403速率限制响应,表示您应该重试请求。

  3. 等待1 + random_number_milliseconds秒并重试请求。

  4. 接收HTTP 403速率限制响应,您应该重试请求。

  5. 等待2 + random_number_milliseconds秒,然后重试请求。

  6. 接收HTTP 403速率限制响应,您应该重试请求。

  7. 等待4 + random_number_milliseconds秒,然后重试请求。

  8. 接收HTTP 403速率限制响应,您应该重试请求。

  9. 等待8 + random_number_milliseconds秒,然后重试请求。

  10. 接收HTTP 403速率限制响应表示您应该重试请求。

  11. 等待16 + random_number_milliseconds秒,然后重试请求。

  12. 停止。报告或记录错误。


I have read the gmail api quota explanation here (https://developers.google.com/gmail/api/v1/reference/quota), but am still having troubles understanding what causes us to go over the limit.

Question 1: What is a user in a per user quota? I am not sure if the user is an individual gmail user, or a service client using the gmail api.

Question 2: We've seen the following error a few times, but don't see any obvious limit we've hit.

"error": {
 "errors": [
  {
   "domain": "usageLimits",
   "reason": "rateLimitExceeded",
   "message": "Rate Limit Exceeded"
  }
 ],
 "code": 429,
 "message": "Rate Limit Exceeded"
}

We were under 250 units/s and 25,000 units/100s. We're only using history.list and message.get calls no sending or modifications.
Is there some other quota I am missing?

解决方案

  1. User quota is based upon the account you are accessing. So it would be the GMail account. Sometimes you can trick it by sending a random quotaUser but this doesn't always work Google also uses your IP address to track quota I suspect.

  2. User rate limit is flood protection you are going to fast.

Per User Rate Limit 250 quota units per user per second, moving average (allows short bursts)

Exceeding a rate limit will cause an HTTP 403 or HTTP 429 Too Many Requests response and your app should respond by retrying with exponential backoff.

Googles calculations are not perfect you could be sending more or less and still hit this quota. Just implementexponential backoff.

Exponential backoff

The flow for implementing simple exponential backoff is as follows:

  1. Make a request to the API.
  2. Receive an HTTP 403 rate-limited response, which indicates you should retry the request.
  3. Wait 1 + random_number_milliseconds seconds and retry the request.
  4. Receive an HTTP 403 rate-limited response, which indicates you should retry the request.
  5. Wait 2 + random_number_milliseconds seconds, and retry the request.
  6. Receive an HTTP 403 rate-limited response, which indicates you should retry the request.
  7. Wait 4 + random_number_milliseconds seconds, and retry the request.
  8. Receive an HTTP 403 rate-limited response, which indicates you should retry the request.
  9. Wait 8 + random_number_milliseconds seconds, and retry the request.
  10. Receive an HTTP 403 rate-limited response, which indicates you should retry the request.
  11. Wait 16 + random_number_milliseconds seconds, and retry the request.
  12. Stop. Report or log an error.

这篇关于了解Gmail API配额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆