Google 云存储中的速率限制
Rate limiting in Google Cloud Storage
在每一分钟结束时,我的代码总共上传 20 到 40 个文件(从多台机器,并行大约 5 个文件,直到它们全部上传)到 Google 云存储。我经常收到 429 - Too Many Errors
,如下所示:
java.io.IOException: Error inserting: bucket: mybucket, object: work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/
at com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.wrapException(GoogleCloudStorageImpl.java:1583)
at com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.run(GoogleCloudStorageImpl.java:474)
... 3 more
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 Too Many Requests
{
"code" : 429,
"errors" : [ {
"domain" : "usageLimits",
"message" : "The total number of changes to the object mybucket/work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/ exceeds the rate limit. Please reduce the rate of create, update, and delete requests.",
"reason" : "rateLimitExceeded"
} ],
"message" : "The total number of changes to the object mybucket/work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/ exceeds the rate limit. Please reduce the rate of create, update, and delete requests."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:432)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.run(GoogleCloudStorageImpl.java:471)
... 3 more
我有一些重试逻辑,这有点帮助,但即使经过一些指数退避和最多 3 次重试,我仍然经常遇到错误。
奇怪的是,当我转到 Google Developers Console -> APIs & auth -> APIs -> Cloud Storage API -> Quotas 时,我看到 Per-user limit 102,406.11 requests/second/user
。当我查看“使用情况”选项卡时,它没有显示任何使用情况。
我错过了什么?将文件上传到 GCS 时如何停止速率限制?为什么我的配额如此之高,而我的使用率报告为 0?
当您尝试过于频繁地更新同一个对象时会发生该错误。来自 https://cloud.google.com/storage/docs/concepts-techniques#object-updates:
There is no limit to how quickly you can create or update different objects in a bucket. However, a single particular object can only be updated or overwritten up to once per second.
从你对多台机器同时采取行动的描述来看,我怀疑你所有的机器都试图在同一时刻写入完全相同的对象名称。 GCS 限制每秒对任何一个对象的写入次数(每秒 1 次)。
由于您的对象名称看起来以斜杠结尾,就像它们是一个目录 (work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/
),您是否打算以某个唯一值或机器名称结束它们还是什么,但留下了那一点?
在每一分钟结束时,我的代码总共上传 20 到 40 个文件(从多台机器,并行大约 5 个文件,直到它们全部上传)到 Google 云存储。我经常收到 429 - Too Many Errors
,如下所示:
java.io.IOException: Error inserting: bucket: mybucket, object: work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/
at com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.wrapException(GoogleCloudStorageImpl.java:1583)
at com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.run(GoogleCloudStorageImpl.java:474)
... 3 more
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 429 Too Many Requests
{
"code" : 429,
"errors" : [ {
"domain" : "usageLimits",
"message" : "The total number of changes to the object mybucket/work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/ exceeds the rate limit. Please reduce the rate of create, update, and delete requests.",
"reason" : "rateLimitExceeded"
} ],
"message" : "The total number of changes to the object mybucket/work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/ exceeds the rate limit. Please reduce the rate of create, update, and delete requests."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:432)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl.run(GoogleCloudStorageImpl.java:471)
... 3 more
我有一些重试逻辑,这有点帮助,但即使经过一些指数退避和最多 3 次重试,我仍然经常遇到错误。
奇怪的是,当我转到 Google Developers Console -> APIs & auth -> APIs -> Cloud Storage API -> Quotas 时,我看到 Per-user limit 102,406.11 requests/second/user
。当我查看“使用情况”选项卡时,它没有显示任何使用情况。
我错过了什么?将文件上传到 GCS 时如何停止速率限制?为什么我的配额如此之高,而我的使用率报告为 0?
当您尝试过于频繁地更新同一个对象时会发生该错误。来自 https://cloud.google.com/storage/docs/concepts-techniques#object-updates:
There is no limit to how quickly you can create or update different objects in a bucket. However, a single particular object can only be updated or overwritten up to once per second.
从你对多台机器同时采取行动的描述来看,我怀疑你所有的机器都试图在同一时刻写入完全相同的对象名称。 GCS 限制每秒对任何一个对象的写入次数(每秒 1 次)。
由于您的对象名称看起来以斜杠结尾,就像它们是一个目录 (work/foo/hour/out/2015/08/21/1440191400003-e7ba2b0c-b71b-460a-9095-74f37661ae83/2015-08-21T20-00-00Z/
),您是否打算以某个唯一值或机器名称结束它们还是什么,但留下了那一点?