Mongoose database connection problem

  node.js, question

Database connection (temporarily written on app.js)

var options = {
 server: {
 poolSize: 100,
 auto_reconnect: true,
 keepAlive: 10
 bracket
 bracket
 
 var db = mongoose.connect(settings.MONGODB_URL,options);

Question:

1. Insert data in batch, and it will appear after a period of time:

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

2. When the above error occurs, all relevant database operations will not run. Is the connection between the program and the database broken? Is the database connection set incorrectly, or is it probably a problem with the database?

3. When I have a highly concurrent A/B Testing, the above two phenomena will also occur. What is the reason? Is the connection pool setting incorrect?

First of all, we should pay attention to the problem of connection pool.mongoose.connectIt should be called only once, and the returned object maintains the connection pool. If it is called repeatedly, the connection will be opened and closed continuously, which will greatly affect the performance.
After confirmation, it depends on how much pressure you give and whether you have used up all available resources. You can look at mongodb’s log and how many connections are open at the same time. You can also look at the remaining resources of the machine.