Hi,
I'm really struggling to get performance out of a spatial query. Perhaps I am on the limit of what my hardware can do, but I have a feeling that there is more that can be done.
I'd really appreciate some feedback here. I've been trying to figure out how to speed this up for days to no avail, but then I am noob...
My documents contain:
{
"l" : [ -0.0013, 51.4779 ],
"d" : ISODate("2012-11-14T00:00:00Z"),
"w" : ObjectId("50a292d2abddc1bd89000001"),
"k" : 13
}
I need to query for specific w and k, ranges of d, and boxes (later polygons) containing l.
I'm querying like so:
$ db.locs.find({ l: { $within: { $box: [[lon1, lat1], [lon2, lat2]] } }, w: ObjectId("50a292d2abddc1bd89000001"), k: 13 }).explain()
{
"cursor" : "GeoBrowse-box",
"isMultiKey" : false,
"n" : 11156,
"nscannedObjects" : 11156,
"nscanned" : 11156,
"nscannedObjectsAllPlans" : 11156,
"nscannedAllPlans" : 11156,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 90,
"nChunkSkips" : 0,
"millis" : 1457,
"indexBounds" : {
"l" : [ ]
},
"lookedAt" : NumberLong(621631),
"matchesPerfd" : NumberLong(459159),
"objectsLoaded" : NumberLong(11156),
"pointsLoaded" : NumberLong(41),
"pointsSavedForYield" : NumberLong(0),
"pointsChangedOnYield" : NumberLong(0),
"pointsRemovedOnYield" : NumberLong(0)
}
Above it reports 1457 milliseconds. The logs show the queries sometimes take up to 7 seconds. In any event, 1.4 seconds seems a little slow to me. Is it?
There are 623k documents in the collection (I get only a tiny improvement if I trim that down to 10% of the size):
$ db.locs.stats()
{
"ns" : "development.locs",
"count" : 623129,
"size" : 85332600,
"avgObjSize" : 136.94210990019724,
"storageSize" : 123936768,
"numExtents" : 11,
"nindexes" : 2,
"lastExtentSize" : 37625856,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 113409296,
"indexSizes" : {
"_id_" : 61516224,
"l_2d_d_1_w_1_k_1" : 51893072
},
"ok" : 1
}
These are my indexes:
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "development.locs",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"l" : "2d",
"d" : 1,
"w" : 1,
"k" : 1
},
"unique" : true,
"ns" : "development.locs",
"name" : "l_2d_d_1_w_1_k_1"
}
]
$ version()
version: 2.2.1
Thanks for any help.