[SERVER-8207] $centerSphere query hangs server Created: 17/Jan/13  Updated: 08/Mar/13  Resolved: 08/Mar/13

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 2.2.0
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Anh H. Trinh Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: Linux
Steps To Reproduce:

1. Obtain a large collection (>20mil) of docs with 2d index
2. Perform a query using $centerSphere

Participants:

 Description   

We have a collection with about 27mil objects with 2d index. A single $nearSphere query hangs the server, make it unresponsive to other queries including db.serverStatus() and also hangs mongotop and mongostat.

> db['similar_items.tanhxdiv5ratings_cosinesimilarities.6'].count()
 
27745186
 
>> db['similar_items.tanhxdiv5ratings_cosinesimilarities.6'].getIndexes()
[
...
	{
		"v" : 1,
		"key" : {
			"xy" : "2d"
		},
		"ns" : "osapi_int.similar_items.tanhxdiv5ratings_cosinesimilarities.6",
		"name" : "xy_2d"
	}
...
]

The offending query use a radius of only 300 meters:

		{
			"opid" : 14035479,
			"active" : true,
			"secs_running" : 210,
			"op" : "query",
			"ns" : "osapi_int.similar_items.tanhxdiv5ratings_cosinesimilarities.6",
			"query" : {
				"query" : {
					"xy" : {
						"$within" : {
							"$centerSphere" : [
								[
									-122.3907852172852,
									37.78129802378191
								],
								0.00005
							]
						}
					}
				},
				"$explain" : true
			},
			"client" : "127.0.0.1:47221",
			"desc" : "conn2484",
			"threadId" : "0x7fcb73575700",
			"connectionId" : 2484,
			"locks" : {
				"^" : "r",
				"^osapi_int" : "R"
			},
			"waitingForLock" : false,
			"numYields" : 0,
			"lockStats" : {
				"timeLockedMicros" : {
					
				},
				"timeAcquiringMicros" : {
					"r" : NumberLong(6),
					"w" : NumberLong(0)
				}
			}
		},

The operation grabbed a global lock and render the server useless until someone perform a manual db.killOp().

GDB stack traces are here: https://gist.github.com/4555130

Beside the obvious performance issue of the query, the server must be tolerant against such "query of death". At the very least it should keep the diagnostic tool such as (mongotop, mongostat, db.serverStatus()) functional.



 Comments   
Comment by hari.khalsa@10gen.com [ 07/Feb/13 ]

Have you let the query run to completion, and if so, how long does it take?

I suspect that it's just going to take a long time to look at 27M objects, especially if they're all near the start of the search. The stack traces suggest that it's still doing the search when you interrupt it. The 2d indexing code doesn't give other commands a chance to run during its search. This is a known bug.

If possible, I suggest grabbing a copy of the 2.4RC and trying the 2dsphere index. I suspect it will perform better on this query, and the search is structured to allow other operations.

Comment by Anh H. Trinh [ 25/Jan/13 ]

any idea on how this will move forward?

fix ver is "debugging with submitter", but i haven't got any contact from the assignee, not sure if I can provide anything extra to help here.

also ticket name should s/nearSphere/centerSphere/

Generated at Thu Feb 08 03:16:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.