神刀安全网

Managing long running operations in MongoDB

MongoDB gives you a number of tools to manage long running operations in the system. It is extremely important to keep track of operations running on your production server at any point of time – in some cases you might have rouge queries or index builds that are killing the performance of your server.

The mongodb command which gives you this information is “db.currentOp()”. For more information refer to the MongoDB documentation for db.currentOp() . The command takes parameters to restrict the output by either db, operation, execution time etc

Here is an example output

{   opid: 294,   active: false,   op: "query",   ns: "admin",   query: { "query": {}, orderby: { "$natural": -1 } },   client: "0.0.0.0:0",   desc: "rsMgr",   threadId: "0x7f3e6af3f700",   waitingForLock: false,   numYields: 0,   lockStats: { timeLockedMicros: { R: 1, W: 1 },   timeAcquiringMicros: { r: 1, w: 1 } }

The most interesting fields are

  1. opid – ID of the operation
  2. op    – The operation that is executing
  3. ns    – The database and collection the operation is executing on.
  4. secs_running – The number of seconds the operation has been running

Once you identify the long running operations you might want to terminate them in some cases. The operation you want to use is

db.killOp(<opid>)

It goes without saying that you want to use this command very carefully. Do not terminate operations you do not know about. I personally only feel comfortable terminating long running queries.

If you have operations that are consistently taking a long time MongoDB provides another option – maxTimeMS

E.g. db.find(...).maxTimeMS(30)

If you know you have long running operations that you want to stop after a certain amount of execution time has exceeded use the maxTimeMS option to set a limit on the execution time of this op.

In MongoDirector we understand the importance of this workflow – so we have built it into our admin console. The ‘admin’ console on the cluster details page provides access to the operations list on your mongodb server

Managing long running operations in MongoDB

You can also select a particular operation and choose to terminate it. As always exercise this option with discretion

Managing long running operations in MongoDB

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Managing long running operations in MongoDB

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮