mongodb - mongoose 数据库连接问题
给我你的怀抱
给我你的怀抱 2017-05-02 09:22:49
0
1
600

数据库连接(暂时写在app.js)

var options = {
  server: {
    poolSize: 100,
    auto_reconnect: true,
    keepAlive: 10
  }
}

var db = mongoose.connect(settings.MONGODB_URL,options);

问题:

1.批量插入数据,一段时间后就会出现:

MongoError: connection 95 to xxx.xxx.xxx timed out

2.当出现上面错误的时候,所有相关的数据库操作就不运行了,是程序与数据库的连接断了吗? 是数据库连接设置的不对,还是可能是数据库的问题?

3.当我进行高并发的ab测试后,也会出现上面2的现象,是什么原因呢?是连接池相关设置的不正确吗?

给我你的怀抱
给我你的怀抱

reply all(1)
我想大声告诉你

First of all, pay attention to the connection pool issue. mongoose.connect should only be called once. The returned object maintains the connection pool. If called repeatedly, the connection will be opened and closed continuously, which greatly affects performance.
After confirmation, you should check how much pressure you put on it and whether it has occupied all available resources. You can look at the mongodb log to see how many connections are open at the same time. You can also look at the remaining resources of the machine.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template