mongodb - mongoose database connection problem
给我你的怀抱
给我你的怀抱 2017-05-02 09:22:49
0
1
614

Database connection (temporarily written in app.js)

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

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

Question:

1. Insert data in batches and it will appear after a while:

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

2. When the above error occurs, all related database operations will not run. Is the connection between the program and the database broken? Is the database connection setting wrong, or may it be a database problem?

3. When I conduct a high-concurrency ab test, the above 2 phenomena will also occur. What is the reason? Are the connection pool related settings incorrect?

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

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