【问题标题】:Maximum Number of Request Parameters for fetchAll()fetchAll() 的最大请求参数数
【发布时间】:2021-05-18 06:15:17
【问题描述】:

URLFetchApp.fetchAll() 的一次调用是否有最大数量的提取请求?我对 AppScripts 的经验有限,并且在文档上找不到任何表明请求数量存在限制的信息,但我很想知道是否存在限制。欢迎任何意见。

【问题讨论】:

  • 在我的环境中,我确认可以处理 1000 个请求。 Ref 但是,我认为这种情况可能取决于使用 fetchAll 方法请求的服务器端的规范。

标签: google-apps-script urlfetch


【解决方案1】:

答案:

扩展Tanaike 在他的benchmarking research for UrlFetchApp.fetchAll() 中进行的研究。我能够成功发出 2199 个请求,但更多的请求触发了端点上的速率限制,因此我无法进一步测试。

研究:

在阅读了上述基准后,我使用 Apps Script 看看是否可以找到该方法的限制。我使用httpbin 进行测试,因为这是Google 在示例sn-p for fetchAll(requests) 中提供的:

// Make both a POST request with form data, and a GET request.
var resumeBlob = Utilities.newBlob('Hire me!', 'text/plain', 'resume.txt');
var formData = {
  'name': 'Bob Smith',
  'email': 'bob@example.com',
  'resume': resumeBlob
};
// Because payload is a JavaScript object, it is interpreted as
// as form data. (No need to specify contentType; it defaults to either
// 'application/x-www-form-urlencoded' or 'multipart/form-data')
var request1 = {
  'url': 'https://httpbin.org/post',
  'method' : 'post',
  'payload' : formData
};
// A request may also just be a URL.
var request2 = 'https://httpbin.org/get?key=value';
UrlFetchApp.fetchAll([request1, request2]);

我通过初始化一个长度为 n 的数组并用如下请求填充它来修改它:

function fetchAllTester() {
  var resumeBlob = Utilities.newBlob('Hire me!', 'text/plain', 'resume.txt');
  var formData = {
    'name': 'Bob Smith',
    'email': 'bob@example.com',
    'resume': resumeBlob
  }

  var request1 = {
    'url': 'https://httpbin.org/post',
    'method' : 'post',
    'payload' : formData
  }

  let requests = new Array(1000).fill(request1)

  UrlFetchApp.fetchAll(requests).map(x => console.log(x.getContentText()))
}

我从 1000 开始,因为这已经被证实可以工作。结果如下:

  • 2000 个请求 - 成功
  • 2500 个请求 - HTTP 502 由 httpbin 返回。
  • 2001 个请求 - 有效
  • 2100 个请求 - 成功
  • 2200 个请求 - HTTP 502 由 httpbin 返回。
  • 2199 个请求 - 成功
  • 2199 个请求 - HTTP 502 由 httpbin 返回。

此时发送 2199 个请求似乎是间歇性响应,但出现 HTTP 502: Bad Gateway 错误,指出问题来自 fetchAll() 方法之外。

结论:

似乎UrlFetchApp.fetchAll() 存在限制,那么它就很高。

Quotas for Google Services page,列出的唯一调用限制是:

Feature Consumer (e.g., gmail.com) and G Suite free edition (legacy) Google Workspace accounts
URL Fetch calls 20,000 / day 100,000 / day

因此,根据我所做的测试和 Google 提供的文档,我的假设是该方法仅受常规 Apps 脚本配额的限制;也就是说,消费者账户每天 20,000 次请求,Workspace 账户每天 100,000 次请求。

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多