christkv/node-mongodb-native — Issue #461: Callback didn't get fired when ab tested /w concurrency > 1
Author: baoshan
Created: 2011-12-28 04:01:38+00:00
State: open

When AB test an express app. I noticed when:

ab -n 1000 -c 10 http://127.0.0.1/collection

there'll be 991 completed request, while 9 fails (TIMEOUT); when:

ab -n 1000 -c 5 http://127.0.0.1/collection

there'll be 996 completed request, while 4 fails (TIMEOUT).

The routing handler as follow;

var client = new mongodb.Db('database', server, {});

var x = 0;
app.get('/collection', function(req, res) {
client.open(function(error, client) {
if (error) res.send(error.toString(), 400);
else {
console.log('open', ++x);
var collection = new mongodb.Collection(client, 'collection');
collection.find().sort('order').toArray(function(error, items) {
if (error) res.send(error.toString(), 400);
else res.send(items);
console.log('close', --x);
client.close();
});
}
});
});

The console logging reveals:

open 1
open 2
open 3
open 4
open 5
close 4
close 3
close 2
close 1
close 0
open 1
open 2
open 3
open 4
open 5
close 4
close 3
close 2
close 1
close 0
open 1
open 2
open 3
open 4
open 5
close 4
close 3
close 2
close 1
close 0
open 1
open 2
open 3
open 4
open 5
close 4
close 3
close 2
close 1
close 0
open 1
close 0
open 1
open 2
open 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3
open 4
close 3

Any suggestions?