【问题标题】:Why is mongodb atlas using 25 connections per 1 active client为什么 mongodb atlas 每 1 个活动客户端使用 25 个连接
【发布时间】:2020-07-10 22:29:29
【问题描述】:

我目前正在使用以下代码连接到 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个并发客户端

【问题讨论】:

    标签: mongodb connection mongodb-atlas


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你确定那是来自你的一个连接吗?每个 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 }
      )
      

      【讨论】:

      • 如何检查来自 mongos 和 arbiters 的连接数
      • 添加了我用来连接实际 IP 的代码 sn-p,以及每个 IP 的连接数
      猜你喜欢
      • 1970-01-01
      • 2012-01-18
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多