mongo连接池错误求分析
var http = require(‘http’); var mongodb = require(‘mongodb’); var poolModule = require(‘generic-pool’);
var pool = poolModule.Pool({
name: 'mongodb',
create: function(callback) {
mongodb.MongoClient.connect('mongodb://localhost/test', {
server: {poolSize: 10}
}, function(err, db) {
callback(err, db);
});
},
destroy: function(db) {
db.close();
},
max: 100,
idleTimeoutMillis: 30000,
log: false
});
http.createServer(function(req, res) {
pool.acquire(function(err, db) {
if (err) {
res.statusCode = 500;
res.end(JSON.stringify(err, null, 2));
} else {
db.collection('userinfo').save({name: 'jack'}, function(err, result) {
res.end(JSON.stringify(result, null , 2));
pool.release(db);
});
}
});
}).listen('8888');
console.log('this server is listening on port 8888...');
setTimeout(function() {
for (var i = 0; i < 1000; i++) {
http.get('http://localhost:8888', function(res) {
console.log('request ok...');
});
}
}, 2000);
错误信息:
events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)
3 回复
请全选后,tab。 现在这样是没人看的。
@haozxuan 恩,格式调整了下。 昨天用mongose自带的连接池连续1w次save无压力。上面的generic-pool,不知道问题在哪?
@jackson18 端口被占用