MMAPV1 is the default storage engine of MongoDB before 3.2, after 3.2 The default storage engine is based on memory-mapped files for the WIREDTIGER,MMAPV1 storage engine, which specializes in high-capacity inserts, reads, and updates.
Journal
To ensure that all modifications to the MongoDB dataset are persisted to disk, mongodb default all records are written in the log on disk, and MongoDB write logs are more mundane than write data files. By default, MongoDB writes to the data file on disk every 60 seconds, and the write log file is roughly every 100 milliseconds, and These values are the maximum time interval for their data files, and in more MongoDB application examples, Mongdb and the operating system refresh the data to disk more frequently, so these values are theoretically maximum values. , to change the log file write time interval, see storage.syncperiodsecs , change the log file write time interval to see storage.journal.commitIntervalMs.
When an instance of Mongdb exits, these logs allow mongdb to recover data from the data file and not refresh all changes.
Record Storage Characteristics
All records are written into the disk, and when a document becomes larger than the address space allocated to the disk, MONGDB must assign a new address, and the new address requires MongoDB to move the document and update all the indexes related to this document, This will lead to the need to spend more time updating addresses and organizing storage fragmentation.
Fortunately, in the later version of mongdb3.0, there are changes, by default, in the 3.0 version, the Power of 2 sized allocations is used, and each document in Mongdb is stored in a disk space, This space includes himself and some extra space, and these additional spaces allow document updates to result in growth with the greatest possible reduction in redistribution.
Record Allocation Strategies
MongoDB supports multiple spatial allocation policies, and when allocating a space, these policies determine how Mongod adds an extra space to this doument, because in MongoDB, document can be added after insertion, all records are on disk, An additional space can reduce the need for a document to be re-allocated space in a larger update. The reallocation of update space efficiency is less efficient than on-premises space updates, and the reallocation of space leads to storage fragmentation, so all additional extra (padding stratrgies) policies are exchanged to increase efficiency by reducing fragmentation.
Different policies support different workloads, and lead to storage fragmentation is better effective for inserting updates and deletions of workloads, exact fit allocations (exact allocation) is a good strategy for a workload that is not updated and deleted.
Power of 2 sized allocations
MongoDB uses the power of 2 sized allocations's allocation policy to MMPAPV1 in later versions of 3.0, and each space is 2 exponential bit (for example: 32,64,128,256,512 ... 2MB), since the size of the document exceeds 2MB, the allocated space is raised to a multiple of 2MB.
The power of 2 sizes has the following key attributes:
* Can effectively re-release free space to reduce fragmentation. Converts a specific space size into a set of fixed-size additions, and the inserted data is stored in a space that may be deleted by an earlier document or moved to create.
* Can reduce the movement, add additional decorative space to a document without the need to move it can grow space. In addition, it saves the cost of moving, without needing to update the index. Although the power of 2 sizes strategy minimizes movement, it cannot be completely eliminated.
No Padding Allocation Strategy
For some collections work does not change the size of the document, such as insert and update work, these work does not increase the size of the file, this time the power of the 2 sizes strategy is useless, you can use the collmod command or The Db.createcollection () method is also used with the Nopadding object.
Prior to 3.0, MONGDB used an allocation strategy that included the dynamic calculation of padding as a document size factor.
Memory use
Using MMAPV,MONGODB to automatically use the free memory of all machines as its cache, the system Resource Monitor monitors the memory usage of MongoDB, which is unexpectedly the MongoDB will use as much free memory as possible if other processes suddenly require a large amount of memory from the server, MONGDB will cache memory to other processes.
Strictly speaking, the operating system of the virtual memory subsystem manages MONGDB memory, which unexpectedly mongodb will use as much free memory as possible, according to the actual need of memory and disk for data exchange, to deploy sufficient memory to enable the application to work the data set with sufficient RAM to make MongoDB Achieve the best performance.
[MongoDB]: MMAPv1 Storage Engine