-
-
Save comerford/da8c8c0eeaae4e134d23 to your computer and use it in GitHub Desktop.
Dead cursor repro - Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mongodb 2.6.4, config file | |
storage: | |
dbPath: "/data/db/264" | |
systemLog: | |
destination: file | |
path: "/data/db/264/mongodb.log" | |
processManagement: | |
fork: true | |
// bulk insert a bunch of data into twitter.tweets | |
use twitter; | |
var bulk = db.tweets.initializeUnorderedBulkOp(); start = new Date(); for(var i = 0; i < 500000; i++){bulk.insert({"_id" : i, id : new ObjectId()})}; bulk.execute({w:1}); end = new Date(); print(end - start); | |
// Test app.js - using mongo native 2.0.x driver | |
var MongoClient = require('mongodb').MongoClient; | |
var mongoUrl = 'mongodb://localhost/twitter'; | |
MongoClient.connect(mongoUrl, function(err, db) { | |
if (err) return console.error(err); | |
var collection = db.collection('tweets'); | |
// 200k limit seems to be needed to trigger, lesser limits are OK | |
collection.find({}, {"_id" : 0, id : 1}).limit(200000).forEach(function(tweet) { | |
// note: setting batch size low, like so triggers the dead cursor messages early | |
// collection.find({}, {"_id" : 0, id : 1}).batchSize(8000).limit(200000).forEach(function(tweet) { | |
// otherwise it errors when it hits the 4MiB limit (see log lines from mongod later) | |
console.log(tweet.id); | |
}, function(err) { | |
if (err) console.error(err); | |
db.close(); | |
}); | |
}); | |
// log lines from the app: | |
5446942542aa4250a78f4c35 | |
5446942542aa4250a78f4c36 | |
5446942542aa4250a78f4c37 | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
{ [MongoError: cursor is dead] name: 'MongoError', message: 'cursor is dead' } | |
// log lines from mongod - note reslen | |
2014-10-21T18:50:32.548+0100 [conn50] query twitter.tweets planSummary: COLLSCAN cursorid:30362014860 ntoreturn:200000 ntoskip:0 nscanned:199728 nscannedObjects:199728 keyUpdates:0 numYields:0 locks(micros) r:120400 nreturned:199728 reslen:4194308 120ms | |
2014-10-21T18:55:01.597+0100 [conn56] query twitter.tweets planSummary: COLLSCAN cursorid:31266586339 ntoreturn:200000 ntoskip:0 nscanned:199728 nscannedObjects:199728 keyUpdates:0 numYields:0 locks(micros) r:109383 nreturned:199728 reslen:4194308 109ms | |
// tried with each instead of foreach, hangs now, but at the exact same spot | |
var MongoClient = require('mongodb').MongoClient; | |
var mongoUrl = 'mongodb://localhost/twitter'; | |
MongoClient.connect(mongoUrl, function(err, db) { | |
if (err) return console.error(err); | |
var collection = db.collection('tweets'); | |
var cursor = collection.find({}, {"_id" : 0, id : 1}); | |
cursor.limit(200000).each(function(err, docs) { | |
console.log(docs.id); | |
if (err) console.error(err); | |
if (docs == null) { | |
db.close(); | |
}; | |
}); | |
}); | |
// this time had to Ctrl-C | |
5446942542aa4250a78f4c35 | |
5446942542aa4250a78f4c36 | |
5446942542aa4250a78f4c37 | |
^C | |
real 5m15.008s | |
// monggod logs are the same | |
2014-10-21T20:00:06.097+0100 [conn87] getmore twitter.tweets cursorid:32151774517 ntoreturn:0 keyUpdates:0 numYields:0 locks(micros) r:113293 nreturned:199728 reslen:4194308 113ms | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment