提高了Google Drive API每用户限制,仍然收到userRateLimitExceeded错误 [英] Raised Google Drive API Per-user limit, still getting userRateLimitExceeded errors

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

问题描述

与基本上就是防洪。它用于防止人们发送很多请求来加快速度。


表示已超出用户费率限制。最高费率
限制为每个IP地址10个点。在Google
Developers Console中设置的默认值为每个IP地址1 qps。您可以在Google Developers Console中将此
限制增加到最大10 qps。


您需要减慢代码通过实施指数退款


  1. 向API发出请求
  2. 接收具有可重试错误代码的错误响应

  3. 等待1s + random_number_milliseconds秒

  4. 重试请求

  5. 接收具有可重试错误代码的错误响应
  6. >
  7. 等待2s + random_number_milliseconds秒

  8. 重试请求

  9. 接收具有可重试错误代码

  10. 等待4s + random_number_milliseconds秒

  11. 重试请求

  12. 接收具有可重试错误的错误响应code

  13. 等待8s + random_number_milliseconds秒

  14. 重试请求t

  15. 接收具有可重试错误代码的错误响应

  16. 等待16s + random_number_milliseconds秒

  17. 重试请求

  18. 如果仍然出现错误,请停止并记录错误。 这个想法是,每当你看到那个错误,你会等几秒钟,然后尝试再发送一次。如果再次出现错误,请稍等一会儿。

    配额用户

    现在我不确定您的应用程序的工作方式,如果所有任务都来自同一个IP,这可能会导致您的问题。正如您在配额中所看到的,您每秒/每个用户获得10次请求。 Google如何知道其用户?他们看着IP地址。如果所有reuqest都来自同一个IP,那么它的一个用户和你被锁定为每秒10个请求。



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


    quotaUser - 替代userIp。 链接


    1. 允许您执行每个用户的配额即使在用户的IP地址未知的情况下也是如此。例如,可能发生
      的应用程序,这些应用程序代表
      用户在App Engine上运行cron作业。

    2. 您可以选择任何唯一标识用户,但限制为40个字符。

    3. 如果两者都提供,则覆盖userIp。

    4. 了解更多关于上限用法的信息。 b




      如果您在每个请求上发送不同的报价单,例如说一个随机数,那么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每用户限制,仍然收到userRateLimitExceeded错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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