MongoDB location Query Memory usage optimization detailed

Source: Internet
Author: User
Tags memory usage mongodb

The production environment instance frequently OOM, the investigation discovery mainly by some $near query causes, the query resembles follows, in which the LATLNG field has established 2d index.

{
"Find": "UserData",
' Filter ': {
"LATLNG": {
"$near": [
116.34642045073839,
39.87082232130999
],
"$maxDistance": 0.9009009009009009
}
},
"Ntoreturn": 10000
}

The official explanation is that the $near need to sort, actually from the center point, constantly going out to find the nearby points, so $near cursor will cache the results. The default timeout for MongoDB cursor is 10 minutes, so if the total amount of memory that is open cursor cache exceeds the total memory in 10 minutes, OOM will occur.

For the above problems, the application has the following 2 ways to optimize memory usage

Set a smaller cursor timeout

Set Mongod–setparameter cursortimeoutmillis=60000 on startup, or you can put it in a configuration file
Modify Db.runcommand Online ({setparameter:1, cursortimeoutmillis:60000})
Find time to set the {singebatch:true} option, so that Mongod immediately after the query shutdown cursor, this method only applies to the cursor do not need to Getmore query.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.