[Mr. Zhao Qiang] memory engine of mongodb

Time:2020-8-14

[Mr. Zhao Qiang] memory engine of mongodb

1、 Overview of storage engine of mongodb

Storage engine is the core component of mongodb, which is responsible for managing how data is stored on disk and memory. Since mongodb version 3.2, mongodb supports multi data storage engine. The storage engines supported by mongodb include wiredtiger, mmapv1 and in memory. Since mongodb version 3.2, wiredtiger has become mongdb’s default storage engine, which is used to persist data to hard disk files. Currently, mongodb supports the following three storage engines:

  • WiredTigerA kind of : wiredtiger provides document level concurrency control, checkpoint, data compression and native encryption. Since mongodb version 3.2, wiredtiger has become mongdb’s default storage engine.
  • MMAPv1A kind of Before mongodb 3.2, mmapv1 was the default data storage engine.
  • In-Memory Storage EngineA kind of : the in memory storage engine stores data in memory. Except for a small amount of metadata and diagnostic logs, the in memory storage engine will not maintain any data stored on the hard disk (on disk data), avoid IO operation of disk and reduce the delay of data query.

2、 In memory storage engine

The in memory storage engine stores data in memory. Except for a small amount of metadata and diagnostic logs, the in memory storage engine will not maintain any on disk data stored on the hard disk, avoiding disk IO operations and reducing data query latency.
Use the following statement to specify the in memory storage engine:

mongod --storageEngine inMemory --dbpath <path>

explain:

  • About the — dbpath parameter: Although the in memory storage engine does not write data to the file system, it needs to use — dbpath to maintain a small amount of metadata and diagnostic logs.
  • About memory usage: – inmemorysizegb sets the amount of memory occupied. The default value is: 50% of ram-1gb. Specifies the amount of memory data used by in memory storage engine, in GB.
  • About persistence: because of in memory The storage engine does not store data persistently. It only stores the data in memory. The read and write operations are completed directly in the memory, and the data will not be written to the disk file. Therefore, there is no need for a separate log file. There is no problem of logging and waiting for data persistence. When the mongodb instance is shut down or the system is terminated abnormally, all the data stored in the memory will be lost Lost.

The startup process is shown in the following figure:

[Mr. Zhao Qiang] memory engine of mongodb

[Mr. Zhao Qiang] memory engine of mongodb