答案:
扩展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 次请求。
参考资料: