为什么 mongodb atlas 每 1 个活动客户端使用 25 个连接

Why is mongodb atlas using 25 connections per 1 active client

我目前正在使用以下代码连接到 mongodb atlas

exports.connectToMongoose = async() =>{
try{
    const result = await  mongoose.connect(process.env.mongodbURL,{
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex:true,
        useFindAndModify:false
    })
}

const connectionResult = await mongooseConnection.connectToMongoose();

虽然只有我一个用户登录。我可以看到 mongodb atlas 正在使用 500 个可用连接中的 25 个连接。为什么每个客户端使用 25 个连接,这是否意味着 mongodb 图集只能处理 20 个并发客户端

你确定那是你的一个连接吗?每个 Mongo 服务器都会有来自集群中其他服务器的多个连接,例如 Mongos 和 Arbiters,以及健康检查和监控。

不久前发现了这个,它提供了连接和它们来自的 IP 的快照.. 如果这有帮助

db.currentOp(true).inprog.reduce((accumulator, connection) => {    
    ipaddress = connection.client ? connection.client.split(":")[0] : "Internal"; 
    if(typeof accumulator[ipaddress] == "undefined"){
        accumulator[ipaddress]= {"active":0, "inactive":0};
    }     
    if(connection.active==true) {
        accumulator[ipaddress]["active"] = (accumulator[ipaddress]["active"] || 0) + 1;     
        accumulator["ACTIVE"] = (accumulator["ACTIVE"] || 0 ) +1;   
    } else {     
        accumulator[ipaddress]["inactive"] = (accumulator[ipaddress]["inactive"] || 0) + 1;     
        accumulator["INACTIVE"] = (accumulator["INACTIVE"] || 0 ) +1;    
    }    
    accumulator["TOTAL_CONNECTION_COUNT"]++;   
    return accumulator;  
},  
{ TOTAL_CONNECTION_COUNT: 0 }
)

db.serverStatus().connections 这可能有助于获取从您的客户端到您的服务器或集群中的主节点的总连接数