MongoDB kill慢查询的操作
MongoDB kill慢查询的操作
[cpp]
很多时候,有些慢查询导致MongoDB压力很大, 花了点时间写了个脚本循环kill些慢查询操作.
[cpp]
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;
} www.zzzyk.com
memProg=db.currentOP().inprog[i];
op = memProg.op;
opid = memProg.opid;
print(i); www.zzzyk.com
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!");
}
}
}
}
www.zzzyk.com
运行方式:
[cpp]
./mongo 10.15.107.154:30000 < ./Self-Script/killSlow.js
作者 crazyjixiang