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 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:
?
Note: from MongoDB1.8.3 starts, MongoDB automatically sets up the stack at startup.
Original link: http://nosqldb.org/topic/50ca8a50ee680fee790001f2