Buscar

jueves, 22 de enero de 2015

MongoDB for DBA's 3/7. Performance. Homeworks

Homework 3.1

Start a mongod server instance (if you still have a replica set, that would work too).
Next, download the handout and run:
mongo --shell localhost/performance performance.js
> homework.init()
>
Build an index on the "active" and "tstamp" fields. You can verify that you've done your job with
db.sensor_readings.getIndexes()

db.sensor_readings.ensureIndex({ "active" :1, "tstamp" :1 },{"name" :"act_tstamp.idx" })
When you are done, run:
homework.a()
and enter the numeric result below (no spaces).
Note: if you would like to try different indexes, you can usedb.sensor_readings.dropIndexes() to drop your old index before creating a new one. (For this problem you will only need one index beyond the _id index which is present by default.)

Result: 3

Homework 3.2

In a mongo shell run homework.b(). This will run in an infinite loop printing some output as it runs various statements against the server.
We'll now imagine that on this system a user has complained of slowness and we suspect there is a slow operation running. Find the slow operation and terminate it.
In order to do this, you'll want to open a second window (or tab) and there, run a second instance of the mongo shell, with something like:
$ mongo --shell localhost/performance performance.js
Keep the other shell with homework.b() going while this is happening. Once you have eliminated the slow operation, run (on your second tab):
> db.currentOp()
{
"inprog" : [
{
"opid" : 101,
"active" : true,
"secs_running" : 168,
"microsecs_running" : NumberLong(168262180),
"op" : "update",
"ns" : "performance.sensor_readings",
"query" : {
"$where" : "function(){sleep(500);return false;}"
},
"client" : "127.0.0.1:36365",
"desc" : "conn5",
"threadId" : "0xaf8f7b40",
"connectionId" : 5,
"locks" : {
"^" : "w",
"^performance" : "W"
},
"waitingForLock" : false,
"numYields" : 46,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(0),
"w" : NumberLong(330834998)
},
"timeAcquiringMicros" : {
"r" : NumberLong(0),
"w" : NumberLong(1771)
}
}
}
]

}

> db.killOp(101)

{ "info" : "attempting to kill op" }

> db.currentOp()
{ "inprog" : [ ] }

homework.c()

and enter the output below. Once you have it right and are ready to move on, ctrl-c (terminate) the shell that is still running the homework.b() function.

> homework.c()

12

Homework 3.3

Compact the performance.sensor_readings collection, with paddingFactor set to 1.0. Then run homework.d() and enter the result below.
Note: If you happen to be running a replica set, just compact on the primary and run homework.d() on the primary. You may need to use the force:true option to run compact on a primary. You may also want to look at paddingFactor in the docs. Prior to 2.6, you would have been able to do this problem without paddingFactor, but now that powerOfTwoSizes is on by default, you'll need to use it in order to fully compact the collection. 


> db.runCommand({"compact" : "sensor_readings", "paddingFactor" : 1 })
{ "ok" : 1 }

> homework.d()


21


No hay comentarios:

Publicar un comentario