MongoDB Connections and connectivity optimization

Source: Internet
Author: User
Tags mongodb server server memory

The default number of connections per connection takes up 10M of memory

Ulimit-a View Stack size

MongoDB server memory to meet connection overhead + data size + index size

That is, the number of connections overhead + Hotspot Data + index

Problems with too many connections:

If you encounter an error message similar to the following in the log:

?
1 "too many open files"
?
1 "too many open connections"

This means that there are too many open connections, and there are two places that limit the number of Mongod/mongos connections:

Operating system Ulimit limit, you can use Ulimit to see open files, whether large enough. The default open files under Linux are 1024, which is often too small for service.

The limitations of MongoDB itself

MongoDB (Mongod/mongos) at boot time, there is a parameter is –maxconns, used to specify the maximum number of connections, the default is 20000, is also the upper limit of mongod support (hard-coded, cannot be modified). If you reach 20,000, you need to optimize the data/index of MONGODB, or you need to extend the DB to support a larger number of concurrent numbers, and if this error occurs when the parameter limit is less than 20,000, you only need to adjust the parameters. 2.5.0 Remove the 20,000 limit, see https://jira.mongodb.org/browse/SERVER-8943

Connection Number optimization:

To query the number of connections via serverstatus:

?
1 mongo> db.serverStatus().connections

Each connection is a thread and requires a stack,linux the default stack setting is generally larger:

?
1 shell> ulimit -a | grep stack stack size              (kbytes, -s) 10240

As for MongoDB's actual stack size, it can be confirmed with the following command (in K):

?
1 shell> cat /proc/$(pidof mongod)/limits | grep stack | awk -F ‘size‘‘{print int($NF)/1024}‘

If the stack is too large (for example, 10240K) it doesn't make sense, simply compare the size and RSS in the command result:

?
1 shell> cat /proc/$(pidof mongod)/smaps | grep 10240 -A 10

The amount of memory that all connections consume is quite staggering, and it's recommended to make the stack smaller, say 1024:

?
1 shell> ulimit -s 1024

Note: from MongoDB1.8.3 starts, MongoDB automatically sets up the stack at startup.

Original link: http://nosqldb.org/topic/50ca8a50ee680fee790001f2

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.