Optimized connection optimization for MongoDB performance

Source: Internet
Author: User
Tags mongodb

After the new Web Machine node was added to the project, it was found that the performance of its MongoDB cluster was beginning to suffer, and the response time of MongoDB became very long during the peak period of the request.

The monitoring found that the number of MongoDB connections reached around 1100~1500 at its peak time, because each connection needed to use 10M (stack size defaults to 10240) of memory, which resulted in considerable memory overhead.

Boxedice is handled by optimizing the connection pool, controlling the number of connections by about 800, and then modifying the kernel's stack size value from the default of 10M to 1M, so that the memory consumed by the connection is greatly reduced.


If you have too many MongoDB connections, you can drag performance and query the number of connections by Serverstatus:

Mongo> db.serverstatus (). connections

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

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):

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:

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:

Shell> ulimit-s 1024

Note: Starting with MongoDB1.8.3, MongoDB will automatically set up the stack at startup.

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.