Skip to main content
 首页 » 编程设计

python之Google Cloud Storage 的 URLFetch 速率限制

2025年05月04日9wuhuacong

情况

我们使用 Cloud Storage 来存储大型 Elasticsearch 结果(来自聚合)。

为了并行处理这些大型聚合,我们将它们存储为多行 JSON 转储。

因此,为了执行并行处理,许多实例将同时打开此文件,因此,由于此记录的限制,达到了 URLFetch 速率限制 :

and the calls count against your URL fetch quota, as the library uses the URL Fetch service to interact with Cloud Storage.

这是产生的异常:

这是打开文件的代码:

import cloudstorage as gcs 
 
def open_file(path, mode, **kwargs): 
    f = gcs.open(path, mode=mode, **kwargs) 
    if not f: 
        raise Exception("File could not be opened: %s" % path) 
 
    return f 

问题

我们需要一种与 Cloud Storage 通信的方法来绕过 URLFetch 配额和速率限制,否则我们将无法有效地执行并行处理。

是否有一种不通过 URLFetch 路由的 App Engine 读取 GCS 文件的方法,就像数据存储 API 不会产生 url 提取速率限制一样?

请您参考如下方法:

不确定这种方法是否与您的应用程序兼容/可用,但是这里...

在并行聚合处理期间,您可以使用 GAE 数据存储来存储中间聚合结果(更宽松的配额),而不是将结果直接汇集到 GCS 文件,并且仅(在需要时组装并)在之后将最终结果发送到 GCS聚合在单个(或几个)GCS 请求中完成。