Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save demesew/0d8cd012c5a09285e46c7acebf1b0a4d to your computer and use it in GitHub Desktop.

Select an option

Save demesew/0d8cd012c5a09285e46c7acebf1b0a4d to your computer and use it in GitHub Desktop.

Revisions

  1. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 28 additions and 31 deletions.
    59 changes: 28 additions & 31 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -97,34 +97,31 @@ db.system.profile.aggregate(
    "avg response time":{$avg:"$millis"}
    }});

    db.system.profile.aggregate(
    [
    { $project : {
    "op" : "$op",
    "millis" : "$millis",
    "timeAcquiringMicrosrMS" : { $divide : [ "$lockStats.timeAcquiringMicros.r", 1000 ] },
    "timeAcquiringMicroswMS" : { $divide : [ "$lockStats.timeAcquiringMicros.w", 1000 ] },
    "timeLockedMicrosrMS" : { $divide : [ "$lockStats.timeLockedMicros.r", 1000 ] },
    "timeLockedMicroswMS" : { $divide : [ "$lockStats.timeLockedMicros.w", 1000 ] } }
    },
    { $project : {
    "op" : "$op",
    "millis" : "$millis",
    "total_time" : { $add : [ "$millis", "$timeAcquiringMicrosrMS", "$timeAcquiringMicroswMS" ] },
    "timeAcquiringMicrosrMS" : "$timeAcquiringMicrosrMS",
    "timeAcquiringMicroswMS" : "$timeAcquiringMicroswMS",
    "timeLockedMicrosrMS" : "$timeLockedMicrosrMS",
    "timeLockedMicroswMS" : "$timeLockedMicroswMS" }
    },
    { $group : {
    _id : "$op",
    "average response time" : { $avg : "$millis" },
    "average response time + acquire time": { $avg: "$total_time"},
    "average acquire time reads" : { $avg : "$timeAcquiringMicrosrMS" },
    "average acquire time writes" : { $avg : "$timeAcquiringMicroswMS" },
    "average lock time reads" : { $avg : "$timeLockedMicrosrMS" },
    "average lock time writes" : { $avg : "$timeLockedMicroswMS" } }
    }
    ]
    );

    db.system.profile.aggregate([
    { $project : {
    "op" : "$op",
    "millis" : "$millis",
    "timeAcquiringMicrosrMS" : { $divide : [ "$lockStats.timeAcquiringMicros.r", 1000 ] },
    "timeAcquiringMicroswMS" : { $divide : [ "$lockStats.timeAcquiringMicros.w", 1000 ] },
    "timeLockedMicrosrMS" : { $divide : [ "$lockStats.timeLockedMicros.r", 1000 ] },
    "timeLockedMicroswMS" : { $divide : [ "$lockStats.timeLockedMicros.w", 1000 ] } }
    },
    { $project : {
    "op" : "$op",
    "millis" : "$millis",
    "total_time" : { $add : [ "$millis", "$timeAcquiringMicrosrMS", "$timeAcquiringMicroswMS" ] },
    "timeAcquiringMicrosrMS" : "$timeAcquiringMicrosrMS",
    "timeAcquiringMicroswMS" : "$timeAcquiringMicroswMS",
    "timeLockedMicrosrMS" : "$timeLockedMicrosrMS",
    "timeLockedMicroswMS" : "$timeLockedMicroswMS" }
    },
    { $group : {
    _id : "$op",
    "average response time" : { $avg : "$millis" },
    "average response time + acquire time": { $avg: "$total_time"},
    "average acquire time reads" : { $avg : "$timeAcquiringMicrosrMS" },
    "average acquire time writes" : { $avg : "$timeAcquiringMicroswMS" },
    "average lock time reads" : { $avg : "$timeLockedMicrosrMS" },
    "average lock time writes" : { $avg : "$timeLockedMicroswMS" } }
    }
    ]);
  2. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 30 additions and 0 deletions.
    30 changes: 30 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -97,4 +97,34 @@ db.system.profile.aggregate(
    "avg response time":{$avg:"$millis"}
    }});

    db.system.profile.aggregate(
    [
    { $project : {
    "op" : "$op",
    "millis" : "$millis",
    "timeAcquiringMicrosrMS" : { $divide : [ "$lockStats.timeAcquiringMicros.r", 1000 ] },
    "timeAcquiringMicroswMS" : { $divide : [ "$lockStats.timeAcquiringMicros.w", 1000 ] },
    "timeLockedMicrosrMS" : { $divide : [ "$lockStats.timeLockedMicros.r", 1000 ] },
    "timeLockedMicroswMS" : { $divide : [ "$lockStats.timeLockedMicros.w", 1000 ] } }
    },
    { $project : {
    "op" : "$op",
    "millis" : "$millis",
    "total_time" : { $add : [ "$millis", "$timeAcquiringMicrosrMS", "$timeAcquiringMicroswMS" ] },
    "timeAcquiringMicrosrMS" : "$timeAcquiringMicrosrMS",
    "timeAcquiringMicroswMS" : "$timeAcquiringMicroswMS",
    "timeLockedMicrosrMS" : "$timeLockedMicrosrMS",
    "timeLockedMicroswMS" : "$timeLockedMicroswMS" }
    },
    { $group : {
    _id : "$op",
    "average response time" : { $avg : "$millis" },
    "average response time + acquire time": { $avg: "$total_time"},
    "average acquire time reads" : { $avg : "$timeAcquiringMicrosrMS" },
    "average acquire time writes" : { $avg : "$timeAcquiringMicroswMS" },
    "average lock time reads" : { $avg : "$timeLockedMicrosrMS" },
    "average lock time writes" : { $avg : "$timeLockedMicroswMS" } }
    }
    ]
    );

  3. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ show profile
    db.system.profile.find({}).sort({$natural:-1})

    // sort by slow queries first
    db.system.profile.find({}).sort({$millis:-1})A.limit(10);
    db.system.profile.find({}).sort({$millis:-1})Alimit(10);

    // anything > 20ms
    db.system.profile.find({"millis":{$gt:20}})
    @@ -39,7 +39,7 @@ db.system.profile.find({"millis":{$gt:20}})
    db.system.profile.find({"ns":"test.foo"}).sort({"millis":-1})

    // regular expression on namespace
    db.system.profile.find( { info: /test.foo/ } ).sort({millis:-1,$ts:-1})
    db.system.profile.find( { "ns": /test.foo/ } ).sort({millis:-1,$ts:-1})

    // anything thats moved
    db.system.profile.find({"moved":true})
  4. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ show profile
    db.system.profile.find({}).sort({$natural:-1})

    // sort by slow queries first
    db.system.profile.find({}).sort({$millis:-1})Alimit(10)
    db.system.profile.find({}).sort({$millis:-1})A.limit(10);

    // anything > 20ms
    db.system.profile.find({"millis":{$gt:20}})
  5. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ show profile
    db.system.profile.find({}).sort({$natural:-1})

    // sort by slow queries first
    db.system.profile.find({}).sort({$millis:-1})A.limit(10)
    db.system.profile.find({}).sort({$millis:-1})Alimit(10)

    // anything > 20ms
    db.system.profile.find({"millis":{$gt:20}})
  6. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -29,6 +29,9 @@ show profile
    // sort by natural order (time in)
    db.system.profile.find({}).sort({$natural:-1})

    // sort by slow queries first
    db.system.profile.find({}).sort({$millis:-1})A.limit(10)

    // anything > 20ms
    db.system.profile.find({"millis":{$gt:20}})

  7. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // a list of useful queries for profiler analysis. Starting with the most basic.
    //
    // 2.4 compatible
    //

    // output explained:
  8. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -5,21 +5,21 @@
    // output explained:
    //
    {
    "ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred
    "ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred
    "op" : "query", // the operation type
    "ns" : "game.players", // the db and collection
    "query" : { "total_games" : 1000 }, // query document
    "ntoreturn" : 0, // # docs returned with limit()
    "ntoskip" : 0, // # of docs to skip()
    "query" : { "total_games" : 1000 }, // query document
    "ntoreturn" : 0, // # docs returned with limit()
    "ntoskip" : 0, // # of docs to skip()
    "nscanned" : 959967, // number of docs scanned
    "keyUpdates" : 0, // updates of secondary indexes
    "keyUpdates" : 0, // updates of secondary indexes
    "numYield" : 1, // # of times yields took place
    "lockStats" : { ... }, // subdoc of lock stats
    "nreturned" : 0, // # docs actually returned
    "nreturned" : 0, // # docs actually returned
    "responseLength" : 20, // size of doc
    "millis" : 859, // how long it took
    "client" : "127.0.0.1", // client asked for it
    "user" : "" // the user asking for it
    "user" : "" // the user asking for it
    }


  9. Kenny Gorman revised this gist Aug 11, 2014. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,27 @@
    //
    //

    // output explained:
    //
    {
    "ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred
    "op" : "query", // the operation type
    "ns" : "game.players", // the db and collection
    "query" : { "total_games" : 1000 }, // query document
    "ntoreturn" : 0, // # docs returned with limit()
    "ntoskip" : 0, // # of docs to skip()
    "nscanned" : 959967, // number of docs scanned
    "keyUpdates" : 0, // updates of secondary indexes
    "numYield" : 1, // # of times yields took place
    "lockStats" : { ... }, // subdoc of lock stats
    "nreturned" : 0, // # docs actually returned
    "responseLength" : 20, // size of doc
    "millis" : 859, // how long it took
    "client" : "127.0.0.1", // client asked for it
    "user" : "" // the user asking for it
    }


    // last few entries
    show profile

    @@ -14,6 +35,9 @@ db.system.profile.find({"millis":{$gt:20}})
    // single coll order by response time
    db.system.profile.find({"ns":"test.foo"}).sort({"millis":-1})

    // regular expression on namespace
    db.system.profile.find( { info: /test.foo/ } ).sort({millis:-1,$ts:-1})

    // anything thats moved
    db.system.profile.find({"moved":true})

  10. Kenny Gorman created this gist Aug 11, 2014.
    73 changes: 73 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    // a list of useful queries for profiler analysis. Starting with the most basic.
    //
    //

    // last few entries
    show profile

    // sort by natural order (time in)
    db.system.profile.find({}).sort({$natural:-1})

    // anything > 20ms
    db.system.profile.find({"millis":{$gt:20}})

    // single coll order by response time
    db.system.profile.find({"ns":"test.foo"}).sort({"millis":-1})

    // anything thats moved
    db.system.profile.find({"moved":true})

    // large scans
    db.system.profile.find({"nscanned":{$gt:10000}})

    // anything doing range or full scans
    db.system.profile.find({"nreturned":{$gt:1}})

    //
    // using the agg framework
    //

    // response time by operation type
    db.system.profile.aggregate(
    { $group : {
    _id :"$op",
    count:{$sum:1},
    "max response time":{$max:"$millis"},
    "avg response time":{$avg:"$millis"}
    }});

    // slowest by namespace
    db.system.profile.aggregate(
    { $group : {
    _id :"$ns",
    count:{$sum:1},
    "max response time":{$max:"$millis"},
    "avg response time":{$avg:"$millis"}
    }},
    {$sort: {
    "max response time":-1}
    });


    // slowest by client
    db.system.profile.aggregate(
    {$group : {
    _id :"$client",
    count:{$sum:1},
    "max response time":{$max:"$millis"},
    "avg response time":{$avg:"$millis"}
    }},
    {$sort: {
    "max response time":-1}
    });

    // summary moved vs non-moved
    db.system.profile.aggregate(
    { $group : {
    _id :"$moved",
    count:{$sum:1},
    "max response time":{$max:"$millis"},
    "avg response time":{$avg:"$millis"}
    }});