[SERVER-11516] $near query hangs server. Created: 01/Nov/13  Updated: 29/Jan/15  Resolved: 29/Jan/15

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

Type: Bug Priority: Critical - P2
Reporter: Mark HUANG [X] Assignee: Siyuan Zhou
Resolution: Duplicate Votes: 1
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

EC-2 linux, ubuntu 10.04


Issue Links:
Duplicate
duplicates SERVER-5800 Refactor 2D $geoWithin into new query... Closed
Backwards Compatibility: Fully Compatible
Operating System: Linux
Steps To Reproduce:

1. Create a collection with 0.2 million records, all the location of them should be [-1.0,-1.0].
2. start a mongo shell, db.test.find({loc:{$near:[-1,-1]}}).limit(3), mongo will hang for a long time till the query finished.
3. start another mongo shell, db.test.find().limit(1), the qury will not be excuted until the geo query finished.

Participants:

 Description   

There are 1 million geo-data in my database and 20% of them are [-1.0,-1.0]

I run the simple query db.test.find({lc:{$near:[-1.0,-1.0]}}).limit(1), which is extremely slow. It costs about 20~30 seconds and I think it is because the data will be sorted with $near operation first and then return 1 doc even if all of their locations are the same.

The CPU usage would definitely rises up to 100%. Then the mongo hangs, all the other query has to wait the completion of the geo query.

The problem is likely to: https://jira.mongodb.org/browse/SERVER-8207



 Comments   
Comment by Siyuan Zhou [ 29/Jan/15 ]

With samantha.ritter@10gen.com's script, I am able to reproduce this issue on 2.6. It takes 18291ms to return 3 results on my workstation. On 3.0.0-rc7, it only takes 567ms. Given the fact that near stage has to fetch all 200k documents and sort them before returning to user, the current performance looks reasonable to me. So I would close this as a dup to SERVER-5800.

Comment by Greg Studer [ 18/Apr/14 ]

Some of this may be addressed by refactoring changes in SERVER-5800.

Comment by Samantha Ritter (Inactive) [ 06/Nov/13 ]

Insert 200,000 legacy points, add 2d index, run query:

> db.testnear.insert({ loc: [-1.0,-1.0] })
> db.testnear.ensureIndex({ loc: "2d" })
> db.testnear.find({loc:{$near:[-1,-1]}}).limit(3)

Query does hang server, and queries from another open mongos are blocked until first call returns. Also, query with and without limit() argument seem to take the same amount of time. From the server:

[conn2] query test.testnear query: { loc: { $near: [ -1.0, -1.0 ] } } ntoreturn:3 ntoskip:0 nscanned:3 keyUpdates:0 locks(micros) r:52174559 nreturned:3 reslen:182 52174ms

Opening for triage! Thanks, Mark, for reporting this!

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