Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitoring MongoDB "background operations"?

Tags:

EDIT: Basically I'm looking for some hints on how to understand what background operations are running on my MongoDB instance and possibly reduce/disable them when necessary so they don't interfere with running tests. I've tried mongostat and mongotop but haven't found anything with them that helped me understand what background operations are running and what is initiating them. db.currentOp() consistently returns an empty array when run before I start running my tests.

I regularly run tests while developing with node (mocha, cucumber). Since yesterday, about 25% of the time server initialization fails trying to connect to mongodb with the following error:

**Unhandled rejection MongoError: exception: cannot perform operation: a background operation is currently running for collection** somecollection     at Function.MongoError.create (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)     at /somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66     at bound (domain.js:254:14)     at runBound (domain.js:267:12)     at Callbacks.emit (.../node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3)     at null.messageHandler (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23)     at Socket.<anonymous> (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:294:20)     at Socket.emit (events.js:107:17)     at readableAddChunk (_stream_readable.js:163:16)     at Socket.Readable.push (_stream_readable.js:126:10)     at TCP.onread (net.js:538:20) 

We use pow-mongodb-fixtures to clear the db and fill it with some basic data before running tests, which is where this is happening. AFAIK nothing major changed when this started happening. Any ideas where I can even start researching the source of this error?

like image 934
joniba Avatar asked Nov 19 '15 09:11

joniba


2 Answers

Well I'm not going to mark this as the answer because I was looking for a way to monitor what is happening and figure out the issue through mongo db. Nevertheless, I did figure out the problem. Not the most helpful solution in the world, but it turned out that we were asynchronously starting the server, which would run all the mongoose schemas and thereby check/recreate all indexes, and more or less simultaneously I was running the fixtures code to clear my collections.

In short, don't try to delete collections while creating indexes on them :)

like image 141
joniba Avatar answered Oct 13 '22 06:10

joniba


Your friend in this case would be:

db.currentOp(true) 

Specifying true includes operations on idle connections and system operations.

See here: https://docs.mongodb.org/manual/reference/method/db.currentOp/

like image 20
Roi Tal Avatar answered Oct 13 '22 07:10

Roi Tal