很多时候,有些慢查询导致MongoDB压力很大, 花了点时间写了个脚本循环kill些慢查询操作
代码如下 | 复制代码 |
var j = 0; var _DEF_TIME = 10; //设置慢查询时间 for (var i in db.currentOP().inprog) { var op = ""; var opid; var memProg = {} if (typeof(undefined) == typeof(db.currentOP().inprog[i])) { continue; } memProg = db.currentOP().inprog[i]; op = memProg.op; opid = memProg.opid; print(i); if (op == "query") { if (memProg.hasOwnProperty(‘secs_running’)) { var useTime = memProg.secs_running; if (useTime >= _DEF_TIME) { db.killOp(opid); j++; print("killed " + j + " Query Operation!"); } } } } |