Answer the question
In order to leave comments, you need to log in
Nodejs + mongodb connection at application start or many when needed, dilemma how to be?
Good afternoon, I have logging in my mongo, on average there are 300-1000 calls per minute, each time I create a connection, write down the log and cut myself off.
Should I use one connection at program start?
When I used mysql, there were pool in the mongo pool of connections, as there are no connections in the mysql library.
here's the dilemma...
Answer the question
In order to leave comments, you need to log in
Standard mongodb is all included out of the box.
I took the connection to the start of the program, what we have: we increased the upload speed, the load on the hdd decreased by 15%. (total load was 22-23% )
async.parallel([
function(callback){
console.log('mongodb callback run');
var mongodb_url = 'mongodb://localhost:27017/database';
var options = { server: { auto_reconnect:true, poolSize: 20, socketOptions: { connectTimeoutMS: 2000 } } };
MongoClient.connect(mongodb_url, options ,function(err, db) {
assert.equal(null, err);
mongodb = db;
callback(null,{event:'init_mongo', reason: 'mongodb connection success'});
});
},
// ....
],function(err,result){
app.run() //sertver listen
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question