服务器上的活动连接数已达到最大 [英] Number of active connections on the server reached to max

查看:242
本文介绍了服务器上的活动连接数已达到最大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mongodb和nodejs.我已经在Atlas上托管了mongodb.

I am working with mongodb and nodejs. I have mongodb hosted on Atlas.

我的后端一直运行良好,但是现在有时会卡住,当我在mongodb地图集上看到分析数据时,它显示活动连接的最大数量达到了 100 .

My backend had been working perfectly but now it is sometimes getting stuck and when I see the analytics on mongodb atlas it shows maximum number of active connections reached to 100.

有人可以解释为什么会这样吗?我可以重启连接并使其 0 吗?

Can someone please explain why this is happening? Can I reboot the connections and make it 0?

@Stennie 我曾用猫鼬连接到数据库

@Stennie I have used mongoose to connect to database

这是我的配置文件

const mongooseOptions = {
  useNewUrlParser: true,
  autoReconnect: true,
  poolSize: 25,
  connectTimeoutMS: 30000,
  socketTimeoutMS: 30000
} 

exports.register = (server, options, next) => {
  defaults = Hoek.applyToDefaults(defaults, options)

  if (Mongoose.connection.readyState) {
    return next()
  }

  if (!Mongoose.connection.readyState) {
    server.log(`${process.env.NOED_ENV} server connecting to ${defaults.url} ${defaults.url}`)

    return Mongoose.connect(defaults.url, mongooseOptions).then(() => {
      return next() // call the next item in hapi bootstrap
    })
  }
}

推荐答案

假设由于无服务器标记,您的后端已部署在lambda上.

Assuming your backend is deployed on lambda since serverless tag.

每次调用都会使容器处于空闲状态,以防止冷启动,或者使用现有容器(如果有).您将连接保持打开状态以在调用之间重用它,如最佳做法.

Each invocation will leave a container idle to prevent cold start, or use an existing one if available. You are leaving the connection open to reuse it between invocation, like advertised in best practices.

poolSize为25(?),最大连接数为100,则应限制

With a poolSize of 25 (?) and 100 max connections, you should limit your function concurrency to 4.

保留并发性以防止您的功能使用该区域中所有可用的并发性或使下游资源超载.

Reserve concurrency to prevent your function from using all the available concurrency in the region, or from overloading downstream resources.

更多阅读: https ://www.mongodb.com/blog/post/optimizing-aws-lambda-performance-with-mongodb-atlas-and-nodejs

这篇关于服务器上的活动连接数已达到最大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆