var poolModule = require('generic-pool');
exports.pool = poolModule.Pool({
name : 'mongo',
create : function(callback) {
dbutil.createMongoClient('mongodbtest', function(err, db, client){
callback(err,client);
});
},
destroy : function(client) {
client.close();
},
max : 10,
idleTimeoutMillis :30000,
log : false
});.
===============================================
var server_options = {
auto_reconnect: true
},
db_options = {
native_parser: true,
strict: false,
safe: false
};
var mongo = require("mongodb"),
Server = mongo.Server,
var mongoServer = new mongo.Server('192.168.0.2', 27017,server_options);
{
dbName : '',
db : null,
err:null,
createMongoClient : function(dbname, callback){
this.dbName = dbname;
if(this.db == null){
this.db = new mongo.Db(this.dbName,mongoServer , db_options);
}
this.db.open(function(err,db){
this.db = db;
this.err = err;
if(callback) callback(this.err,this.db,dbutil);
});
}
}
为什么上面这个配置,1000并发60秒,会出现请求没有什么响应(之前还出现过: db object already connecting, open cannot be called multiple times); 当我把操作mongodb的代码注释后, 1000并发,30分钟都没有任何问题;
我也测过: max : 1, idleTimeoutMillis :300,
max : 1,
idleTimeoutMillis :3000,
max : 5,
idleTimeoutMillis :300,
等等.....