Skip to content

Instantly share code, notes, and snippets.

@lloiacono
Created November 17, 2020 16:30
Show Gist options
  • Select an option

  • Save lloiacono/fd0f1dbf98a3adf4c7055265fef0a1a4 to your computer and use it in GitHub Desktop.

Select an option

Save lloiacono/fd0f1dbf98a3adf4c7055265fef0a1a4 to your computer and use it in GitHub Desktop.

Revisions

  1. lloiacono renamed this gist Nov 17, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. lloiacono created this gist Nov 17, 2020.
    16 changes: 16 additions & 0 deletions mongoDBQueryKiller.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // kills long running ops in MongoDB (taking seconds as an arg to define "long")
    // attempts to be a bit safer than killing all by excluding replication related operations
    // and only targeting queries as opposed to commands etc.

    killLongRunningOps = function(maxSecsRunning) {
    currOp = db.currentOp();
    for (oper in currOp.inprog) {
    op = currOp.inprog[oper-0];
    if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
    print("Killing opId: " + op.opid
    + " running for over secs: "
    + op.secs_running);
    db.killOp(op.opid);
    }
    }
    };