When a new Web machine node is added to the project, the performance of its MongoDB cluster is found to be impacted, at the peak of the request, and the MongoDB response time becomes very long.
Monitoring found that the number of connections MongoDB at peak times reached around 1100~1500, which resulted in considerable memory overhead due to the need for each connection to use 10M of memory with a stack size default of 10240.
The Boxedice approach is to first optimize the connection pool, control the number of connections by 800, and then modify the kernel stack size value, from the default 10M to 1M, so that the memory of the connection is greatly reduced.
The number of MONGODB connections can drag down performance and query the number of connections by Serverstatus:
Mongo> db.serverstatus (). connections
Each connection is a thread that requires a stack,linux the default stack setting is generally larger:
Shell> Ulimit-a | grep Stack stack size (Kbytes,-s) 10240
As for the actual stack size used by MongoDB, you can use the following command to confirm (unit: K):
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 control the size and RSS in the command result:
Shell> cat/proc/$ (pidof mongod)/smaps | grep 10240-a 10
The amount of memory consumed by all connections can be staggering, and it's recommended that you set the stack down a little bit, say 1024:
Shell> ulimit-s 1024
Note: Starting at MongoDB1.8.3, MongoDB will automatically set stack at startup.