[英]Making 10,000 HTTP Requests Quickly
I would like to make 10,000 concurrent HTTP requests.我想发出 10,000 个并发 HTTP 请求。 I am currently doing it by using Promise.all
.我目前正在使用Promise.all
来实现。 However, I seem to be rate limited in some way, it takes around 15-30 mins to complete all 10,000 requests.但是,我似乎在某种程度上受到速率限制,完成所有 10,000 个请求大约需要 15-30 分钟。 Is there something in axios or in the http requests in node that is limiting me?节点中的 axios 或 http 请求中是否有限制我的内容? How can I raise the limt if there is one?如果有限制,我如何提高限制?
const axios = require('axios');
function http_request(url) {
return new Promise(async (resolve) => {
await axios.get(url);
// -- DO STUFF
resolve();
});
}
async function many_requests(num_requests) {
let all_promises = [];
for (let i = 0; i < num_requests; i++) {
let url = 'https://someurl.com/' + i;
let promise = http_request(url);
all_promises.push(promise);
}
return Promise.all(all_promises);
}
async function run() {
await many_requests(10000);
}
run();
In Node.js there are two types of threads: one Event Loop (aka the main loop, main thread, event thread, etc.), and a pool of k Workers in a Worker Pool (aka the threadpool).在 Node.js 中,有两种类型的线程:一种是事件循环(也称为主循环、主线程、事件线程等),另一种是 Worker Pool 中的 k 个 Worker 池(又名线程池)。
... ...
The Worker Pool of Node.js is implemented in libuv (docs), which exposes a general task submission API. Node.js 的 Worker Pool 是在 libuv (docs) 中实现的,它公开了一个通用的任务提交 API。
Default UV_THREADPOOLSIZE is 4. You can set UV_THREADPOOLSIZE as link.默认 UV_THREADPOOLSIZE 为 4。您可以将 UV_THREADPOOLSIZE 设置为链接。 Limit of it depend on os, you need check your os:它的限制取决于操作系统,您需要检查您的操作系统:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.