简体   繁体   English

监控MongoDB“后台操作”?

[英]Monitoring MongoDB “background operations”?

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. 编辑:基本上我正在寻找一些关于如何理解我的MongoDB实例上运行的后台操作的提示,并可能在必要时减少/禁用它们,这样它们就不会干扰运行测试。 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. 我已经尝试了mongostatmongotop但没有发现任何与它有关的东西,这些东西帮助我了解了正在运行的后台操作以及启动它们的内容。 db.currentOp() consistently returns an empty array when run before I start running my tests. 在开始运行测试之前, db.currentOp()在运行时始终返回一个空数组。

I regularly run tests while developing with node (mocha, cucumber). 我在使用node(mocha,cucumber)开发时经常运行测试。 Since yesterday, about 25% of the time server initialization fails trying to connect to mongodb with the following error: 从昨天开始,大约25%的服务器初始化尝试连接到mongodb失败,出现以下错误:

**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. 我们使用pow-mongodb-fixture来清除db并在运行测试之前用一些基本数据填充它,这就是发生这种情况的地方。 AFAIK nothing major changed when this started happening. 当这种情况开始发生时,AFAIK并未发生重大变化。 Any ideas where I can even start researching the source of this error? 有什么想法,我甚至可以开始研究这个错误的来源?

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. 好吧,我不打算将此作为答案,因为我正在寻找一种方法来监控正在发生的事情并通过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. 这不是世界上最有用的解决方案,但事实证明我们是异步启动服务器,它将运行所有mongoose模式,从而检查/重新创建所有索引,并且或多或少同时运行fixtures代码以清除我的集合。

In short, don't try to delete collections while creating indexes on them :) 简而言之,在创建索引时不要尝试删除集合:)

Your friend in this case would be: 在这种情况下你的朋友将是:

db.currentOp(true)

Specifying true includes operations on idle connections and system operations. 指定true包括对空闲连接和系统操作的操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM