MongoDB Store Data

Source: Internet
Author: User

To learn more about how MongoDB stores data, one concept must be clear, and that is memeory-mapped Files.

 memeory-mapped Files shows how the database deals with the underlying system.  
    • the memory-mapped file is OS via mmap Create a data file in memory , which maps the file to an area of virtual memory;
    • virtual Memory is an abstraction of physical memory for a process , address space size is 2^64 ;
    • The operating system maps all the data required by the process to this address space (the red line) through Mmap, and then maps the data currently needed for processing to physical memory (gray lines) , which is understood to be in virtual memory when the data is declared. The purpose of a data declaration is to describe what data is used in the process, but it is not necessary to specify what data is used, only that its address does not involve a specific value, i.e. it is not instantiated, and if the object is instantiated, it is mapped to physical memory in virtual memory)
    • When a process accesses a data, if the data is not in virtual memory, the page fault is triggered, and then the OS loads the data into virtual memory and physical memory from the hard disk;
    • If the physical memory is full, triggering the swap-out operation, then some data needs to be written back to the disk, if it is purely memory data, write back to the swap partition, if not write back to the disk.
 MongoDB's storage model 
    • With memory-mapped files, the data to be accessed seems to be in memory, simplifying the logic of MongoDB accessing and modifying data
    • MongoDB reads and writes only deals with virtual memory, leaving all the OS to take care of
    • Virtual Memory size = All file size + some other overhead (connection, stack)
    • If journal is turned on, the virtual memory size is almost doubled
 
    • Benefits of using MMF:
    • 1: Do not manage memory and disk scheduling yourself
    • 2:LRU strategy
    • 3: During restart, the cache is still
 
    • Disadvantages of using MMF:
    • 1:ram use is affected by disk fragmentation, and high read-ahead can also affect
    • 2: Unable to optimize the scheduling algorithm by itself, only using LRU

MongoDB Store Data

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.