MongoDB Memory Analysis

Source: Internet
Author: User

To understand the memory mechanism of MONGO, we should first understand the memory analysis of Linux system.

The first step: First look at the Linux memory parameters are how to say

Total used free shared buffers cachedmem:11912 9045 2866 0 90 3406-/+ buffers/cache:5549 6363 swap:2047 14 2033

Total: Overall physical memory size

Used: How much has been used

Free: How much is left

Buffers:buffers refers to the size of the high-speed buffer area, is a space-size concept, running programs commonly used data, in the first run

The system will temporarily cache them in a high-speed storage area and then read the data directly from this area

Access to these data is much faster than hard drives and memory, so the size of the buffers

The effect of computer speed is great, but the data will automatically disappear after restarting the computer or shutting down the machine.

Cached:cached refers to cached data, which is really something real, such as your usual program, because some data is these

Programs run frequently to be used, the system will make them into files, cache to a specific location, next time you run

The program will automatically read the data to the cached location for the program to run, the area where the data is stored in the computer's

On the hard disk, in theory, read and write speed is unchanged, but also to save the time to look for these data, it can also indirectly

Improve the efficiency of computer operation.

Swap: When physical memory is not enough, the system will cut a piece of space on the physical hard disk and use it as memory.


The real available memory for a Linux host is: real available memory =total-used-buffers-cached

The used shown in the system include buffers and cached size, but the two data can be freed, so the real use of how much is: really used memory =used-buffers-cached


The second step: the system memory said almost, then we look at how the memory of MONGO and the system to cooperate.

First say MONGO is a pit but also a very cool database, why say pit "is because it does not release memory, you have 100G of memory it will give you to eat full"; Why do you say he is cool "because it puts the data in memory, so 100w data query will be very fast";

So how to determine the MONGO machine to the memory is reasonable? Here's the formula: physical Memory >mongo The thermal data +mongo the index data


You can also use the Mongostat command to monitor the memory usage of MongoDB as follows:

Shell> mongostatmapped vsize res faults 940g 1893g 21.9g 0

Where the memory-related fields mean:

Mapped: size of data mapped to memory

Visze: The amount of virtual memory occupied

Res: The amount of physical memory occupied

Note: If the operation cannot be completed in memory, the value of the faults column will not be 0, and the apparent size may have a performance problem.

In the above results, vsize is mapped twice times, and mapped equals the size of the data file, so vsize is the data file twice times, the reason is this, because in this case, MongoDB opened the journal, need to map the data file in memory, If journal is turned off, vsize and mapped are roughly equal.


Reference Document: http://www.ttlsa.com/mongodb/mongodb-and-memory/

This article is from the "Learning to change the Destiny" blog, please make sure to keep this source http://xinsir.blog.51cto.com/5038915/1960750

MongoDB Memory Analysis

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.