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?
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.