Skip to content

Instantly share code, notes, and snippets.

View kgorman's full-sized avatar

Kenny Gorman kgorman

View GitHub Profile
> db.testme.find()
{ "_id" : ObjectId("4d518d60a46e6d320ede66b7"), "userid" : 10, "path" : "10:1002" }
{ "_id" : ObjectId("4d518efba46e6d320ede66b8"), "userid" : 10, "path" : "10:1002:99" }
> db.testme.update({path:/^10:1002/},{$set:{path:"10:1004"}})
> db.testme.find()
{ "_id" : ObjectId("4d518d60a46e6d320ede66b7"), "userid" : 10, "path" : "10:1004" }
{ "_id" : ObjectId("4d518efba46e6d320ede66b8"), "path" : "10:1004", "userid" : 10 }
// what we want is:
131 137 12 0 216 308 0 1550140 1558240 41640 6 2.1 0 0|0|0 723 17:04:05
insert/s query/s update/s delete/s getmore/s command/s flushes/s mapped vsize res faults/s locked % idx miss % q t|r|w conn time
144 150 5 0 237 307 0 1550140 1558240 41640 8 4.6 0 0|0|0 723 17:04:06
136 138 14 0 233 311 0 1550140 1558240 41641 8 2.1 0 0|0|0 723 17:04:07
153 151 10 0 253 331 0 1550140 1558240 41641 9 4.1 0 0|0|0 723 17:04:08
151 150 6 0 257 320 0 1550140 1558240 41631 8 2 0 0|0|0 723 17:04:09
122 130 10 0 216 274 0 1550140 1558240 41632 7 4.2 0 0|0|0 723 17:04:10
insert query update delete getmore command flushes mapped vsize res faults locked % idx miss % qr|qw ar|aw netIn netOut conn time
719 0 0 0 0 1 0 464m 643m 389m 17 5.4 0 0|0 0|0 1m 1k 3 18:18:02
695 0 0 0 0 1 0 464m 643m 390m 17 5.5 0 0|0 0|0 1m 1k 3 18:18:03
706 0 0 0 0 1 0 464m 643m 391m 17 3.9 0 0|0 0|0 1m 1k 3 18:18:04
711 0 0 0 0 1 0 464m 643m 392m 17 2.8 0 0|0 0|0 1m 1k 3 18:18:05
716 0 0 0 0 1 0 464m 643m 393m 17 2.8 0 0|0 0|0 1m 1k 3 18:18:06
720 0 0 0 0 1 0 464m 643m 394m 18 2.6 0 0|0 0|0 1m
@kgorman
kgorman / gist:977320
Created May 17, 2011 20:32
Data Compaction/Locality Example
> db.disktest_noorg.ensureIndex({"userid":-1});
> db.disktest_org.ensureIndex({"userid":-1});
> db.disktest_noorg.find().sort({userid:-1})
{ "_id" : ObjectId("4dd2d82b6a2e502b3043ef33"), "userid" : 49999, "imageid" : 20, "img" : "www.kennygorman.com/foo.jpg", "title" : "This is a sample title", "data" : "79357fb65ba7b87f2632dfe8e098400c" }
{ "_id" : ObjectId("4dd2d82e6a2e502b30442186"), "userid" : 49999, "imageid" : 14, "img" : "www.kennygorman.com/foo.jpg", "title" : "This is a sample title", "data" : "43a98d693fc469b323f2c9033176cd97" }
{ "_id" : ObjectId("4dd2d8316a2e502b30448652"), "userid" : 49999, "imageid" : 18, "img" : "www.kennygorman.com/foo.jpg", "title" : "This is a sample title", "data" : "810c9ca8b61eff972e0d514191874f22" }
{ "_id" : ObjectId("4dd2d82a6a2e502b3043d4d4"), "userid" : 49996, "imageid" : 39, "img" : "www.kennygorman.com/foo.jpg", "title" : "This is a sample title", "data" : "e864723614597f09c6d09469aa3e3235" }
{ "_id" : ObjectId("4dd2d82b6a2e502b3043efcd"), "userid" : 49995, "ima
@kgorman
kgorman / gist:977336
Created May 17, 2011 20:38
Data Density Example Script
// data density example
// shows how storing/sorting data by key can reduce I/O drastically in MongoDB
// diskloc gives file # and offset of a given document, divide by 512 for block #
// 2011 kcg
// start clean
db.disktest_noorg.drop();
db.disktest_org.drop();
// create some random data in non userid dense form
@kgorman
kgorman / gist:979180
Created May 18, 2011 18:27
Fastmod removed?
> x=db.ptest.findOne({userid:10})
{
"_id" : ObjectId("4dd40b37799c16bbf79c1571"),
"userid" : 10,
"imageid" : 62,
"img" : "www.kennygorman.com/foo.jpg",
"title" : "This is a sample title",
"data" : "c6de34f52a1cb91efb0d094653aae051",
"likes" : 10
}
@kgorman
kgorman / gist:979275
Created May 18, 2011 19:02
fastmod example
> x=db.ptest.findOne({userid:10})
{
"_id" : ObjectId("4dd40b37799c16bbf79c1571"),
"userid" : 10,
"imageid" : 62,
"img" : "www.kennygorman.com/foo.jpg",
"title" : "This is a sample title",
"data" : "c6de34f52a1cb91efb0d094653aae051",
"likes" : 10
}
@kgorman
kgorman / gist:979283
Created May 18, 2011 19:07
explain example
> db.ptest.find({userid:10}).explain()
{
"cursor" : "BtreeCursor userid_-1",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
@kgorman
kgorman / gist:979405
Created May 18, 2011 19:58
mongostat example
insert query update delete getmore command flushes mapped vsize res faults locked % idx miss % qr|qw conn repl time
0 56 6 0 11 9 0 508g 517g 42g 70 9.2 0 0|0 798 M 12:55:24
0 74 25 0 38 28 0 508g 517g 42g 59 6.2 0 0|0 798 M 12:55:25
0 68 5 0 8 7 0 508g 517g 42g 22 2.2 0 3|1 798 M 12:55:26
0 57 7 0 17 11 0 508g 517g 42g 62 3 0 0|0 798 M 12:55:27
0 101 32 0 18 34 0 508g 517g 42g 38 8.6 0 4|0 798 M 12:55:28
0 125 33 0 29 38 0 508g 517g 42g 44 8.1 0 0|0 798 M 12:55:29
0 157 29 0 19 31 0 508g 517g 42g 85 7.8
@kgorman
kgorman / d_migrate.cpp
Created May 26, 2011 17:41
chunkMove optimzations
while ( 1 ) {
bool filledBuffer = false;
readlock l( _ns );
Client::Context ctx( _ns );
scoped_spinlock lk( _trackerLocks );
set<DiskLoc>::iterator i = _cloneLocs.begin();
for ( ; i!=_cloneLocs.end(); ++i ) {
if (tracker.ping()) // should I yield?
break;