Mongdb storage principle

Mongdb accesses data very fast and can be used as a cache. At the same time it is also extremely memory-intensive. Almost as much memory is eaten as there is.
At the same time it is also extremely memory-intensive. Almost as much memory is eaten as there is. Why is this happening? This must go deep into the storage principle of mongdb.
The reading process of the traditional database is that if it is reading, it will first read the data in the memory. If not, it will go to the disk to read, read the disk data into the memory,
and then read it from the memory. According to the principle of program locality, only a piece of data near the current data is often read into memory, and other data is not read into memory,
only when needed. If it is a write example, the memory data will be flushed into the memory immediately. But mongdb is different. It
will , so it seems to be very memory-intensive. The advantage of this is to deal almost entirely with memory and try to avoid
reading . If the data is written to the disk, mongdb just writes the data into the memory. As for when the data is written from the memory to the disk, it entrusts this
work to the virtual memory manager of the operating system to handle. Therefore, from the point of view of reading data, since mongdb only reads data from memory,
it is very fast in accessing data. Also because of the direct memory reason, it can be used as a cache. However, there is a problem: that is, the physical material of the
memory is semiconductor material, which is volatile in the storage of data. In the event of a sudden power failure or downtime, the data stored in the memory will be lost.
This is unbearable. To overcome, Journal logs are generated. It flushes the in-memory data to the journal file every so often.
This time interval is adjustable. The shorter the interval, the less data is accidentally lost.
The storage engine is the core of mongdb storage: the function of the storage engine is to map the data on the disk to the memory, or flush the data from the memory to the disk.
There are many kinds of storage engines, and the lock granularity provided is the point of view.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325726374&siteId=291194637