node.js - Nodejs只有4个远程http请求同时执行
问题描述
我正在尝试使用下面的 NodeJS 代码执行多个同时请求,但是从输出中我可以看到下面的请求以 4 组的形式执行。
为什么会这样?
此外,我将默认 libuv 线程池大小更改为 7。
const http = require("http");
const rq = require("request");
http.createServer(function(req, res) {
res.write("Server started");
var start = process.hrtime();
rq("https://stream101.herokuapp.com/5.php", {
pool: {
maxSockets: 20
}
}, (err, res, body) => {
if (res) {
var end = process.hrtime(start);
console.log(body);
console.log("in time : %ds", end[0] + end[1] / 1e9);
}
});
res.end();
}).listen(8081);
这里stream101.herokuapp.com
只是在睡眠 5 秒后回显内容。
这就是我的节点应用程序的启动方式:
set UV_THREADPOOL_SIZE=7 && node index.js
节点控制台输出:
Streaming after 5 seconds
in time : 6.075168388s
Streaming after 5 seconds
in time : 6.079874785s
Streaming after 5 seconds
in time : 6.077171028s
Streaming after 5 seconds
in time : 6.420050492s
Streaming after 5 seconds
in time : 10.966390463s
Streaming after 5 seconds
in time : 10.967194215s
Streaming after 5 seconds
in time : 10.998825902s
Streaming after 5 seconds
in time : 11.42817129s
Streaming after 5 seconds
in time : 16.353070153s
Streaming after 5 seconds
in time : 16.440429564s
Streaming after 5 seconds
in time : 16.643850903s
Streaming after 5 seconds
in time : 16.624362216s
上述测试用例的 Apache 基准测试命令:
ab -n12 -c5 http://localhost:8081/
是否存在与 libuv 线程池相关的问题,因为它可以用于 heruko dns 查询?
解决方案
推荐阅读
- python - 如何将自己模型的权重转移到同一网络但最后一层的分类数量不同?
- mysql - 如何使用 Java 中的休眠在 MySQL 数据库中创建联接表?
- html - 为什么条件渲染不适用于 vuejs 中的表单输入
- c++ - 如何创建 32 位红色纹理字节缓冲区
- soundcloud - 从 SoundCloud 检索所有用户的播放列表,限制为 50?
- sql - 具有 JOIN 和多个订单列的每组最大 N
- javascript - 如何添加 localStorage 来显示和隐藏 div
- excel - 根据列值随机打乱行
- javascript - 如何路由到 ReactJS 中的不同组件
- c++ - 为什么 std::unordered_set operator==() N^2 的复杂性?