提高了 Google Drive API Per-user 限制,仍然出现 userRateLimitExceeded 错误 [英] Raised Google Drive API Per-user limit, still getting userRateLimitExceeded errors

查看:26
本文介绍了提高了 Google Drive API Per-user 限制,仍然出现 userRateLimitExceeded 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于 基本上是防洪.它用于防止人们快速发送许多请求.

<块引用>

表示已超出用户速率限制.最大速率限制为每个 IP 地址 10 qps.Google 中设置的默认值开发人员控制台是每个 IP 地址 1 qps.你可以增加这个在 Google Developers Console 中限制为最大 10 qps.

您需要通过实现 指数退避.

  1. 向 API 发出请求
  2. 接收具有可重试错误代码的错误响应
  3. 等待 1s + random_number_milliseconds 秒
  4. 重试请求
  5. 接收具有可重试错误代码的错误响应
  6. 等待 2s + random_number_milliseconds 秒
  7. 重试请求
  8. 接收具有可重试错误代码的错误响应
  9. 等待 4s + random_number_milliseconds 秒
  10. 重试请求
  11. 接收具有可重试错误代码的错误响应
  12. 等待 8 秒 + random_number_milliseconds 秒
  13. 重试请求
  14. 接收具有可重试错误代码的错误响应
  15. 等待 16 秒 + random_number_milliseconds 秒
  16. 重试请求
  17. 如果仍然出现错误,请停止并记录错误.

我们的想法是,每次看到该错误时,您都会等待几秒钟,然后尝试再次发送它.如果您再次收到错误,请等待更长的时间.

配额用户:

现在我不确定您的应用程序是如何工作的,但是,如果所有任务都来自同一个 IP,这可能会导致您的问题.正如您从配额中看到的那样,您每秒/每个用户会收到 10 个请求.谷歌如何知道它的用户?他们查看 IP 地址.如果您的所有请求都来自同一个 IP,那么它的一个用户并且您被锁定为每秒 10 个请求.

您可以通过将 QuotaUser 添加到您的请求中来解决此问题.

<块引用>

quotaUser - userIp 的替代品. 链接

  1. 即使在用户 IP 地址未知的情况下,您也可以从服务器端应用强制执行每个用户的配额.这可能发生,例如,对于在 App Engine 上运行 cron 作业的应用程序代表用户.
  2. 您可以选择任何唯一标识用户的任意字符串,但限制为 40 个字符.
  3. 如果两者都提供,则覆盖 userIp.
  4. 详细了解上限使用情况.

如果您在每次请求时发送不同的配额用户,比如一个随机数,那么 Google 会认为它是一个不同的用户,并会假定它在 10 秒内只有一个请求.在运行从同一个 IP 请求所有内容的服务器应用程序时,这是绕过 IP 限制的一个小技巧.

Similar to Raising Google Drive API per-user limit does not prevent rate limit exceptions

In Drive API Console, quotas looks like this:

Despite Per-user limit being set to an unnecessarily high requests/sec, I am still getting rate errors at the user-level.

What I'm doing:

I am using approx 8 threads uploading to Drive, and they are ALL implementing a robust exponential back-off of 1, 2, 4, 8, 16, 32, 64 sec back-off respectively (pretty excessive back-off, but necessary imho). The problem can still persists through all of this back-off in some of the threads.

Is there some other rate that is not being advertised / cannot be set?

I'm nowhere near the requests/sec, and still have 99.53% total quota. Why am I still getting userRateLimitExceeded errors?

解决方案

userRateLimitExceeded is flood protection basically. Its used to prevent people from sending to many requests to fast.

Indicates that the user rate limit has been exceeded. The maximum rate limit is 10 qps per IP address. The default value set in Google Developers Console is 1 qps per IP address. You can increase this limit in the Google Developers Console to a maximum of 10 qps.

You need to slow your code down, by implementing Exponential Backoff.

  1. Make a request to the API
  2. Receive an error response that has a retry-able error code
  3. Wait 1s + random_number_milliseconds seconds
  4. Retry request
  5. Receive an error response that has a retry-able error code
  6. Wait 2s + random_number_milliseconds seconds
  7. Retry request
  8. Receive an error response that has a retry-able error code
  9. Wait 4s + random_number_milliseconds seconds
  10. Retry request
  11. Receive an error response that has a retry-able error code
  12. Wait 8s + random_number_milliseconds seconds
  13. Retry request
  14. Receive an error response that has a retry-able error code
  15. Wait 16s + random_number_milliseconds seconds
  16. Retry request
  17. If you still get an error, stop and log the error.

The idea is that every time you see that error you wait a few seconds then try and send it again. If you get the error again you wait a little longer.

Quota user:

Now I am not sure how your application works but, If all the quests are coming from the same IP this could cause your issue. As you can see by the Quota you get 10 requests per second / per user. How does Google know its a user? They look at the IP address. If all your reuqests are coming from the same IP then its one user and you are locked to 10 requests per second.

You can get around this by adding QuotaUser to your request.

quotaUser - Alternative to userIp. Link

  1. Lets you enforce per-user quotas from a server-side application even in cases when the user's IP address is unknown. This can occur, for example, with applications that run cron jobs on App Engine on a user's behalf.
  2. You can choose any arbitrary string that uniquely identifies a user, but it is limited to 40 characters.
  3. Overrides userIp if both are provided.
  4. Learn more about capping usage.

If you send a different quotauser on every reqest, say a random number, then Google thinks its a different user and will assume that its only one request in the 10 seconds. Its a little trick to get around the ip limitation when running server applications that request everything from the same IP.

这篇关于提高了 Google Drive API Per-user 限制,仍然出现 userRateLimitExceeded 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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