About mogodb cach

With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.

Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:

    50% of (RAM - 1 GB), or
    256 MB.

mongodb4.0 document, which roughly means that mongodb uses internal cache and the filesystem cache ,
(1) excuse me, if the memory of the machine is 2g, then, internal catche will occupy 512m according to the above calculation. If the data increases and the memory takes up more than 512m, should we start to enable filesystem cache, to cache the data in free memory at this time?
(2) since both are in memory, Why are there two types of caches? is it true that internal cache occupies memory that cannot be freed and, filesystem cache that cannot be freed will be squeezed out by other services?
(3) are these caches also compressed?

Aug.24,2021

there are almost all the answers upstairs. Add something:
filesystem cache is the behavior of the operating system and is not controlled by the application. If necessary, this part of the cache will be allocated to other processes. Because filesystem cache is a faithful mapping of disk files, and the files stored by MongoDB on disk are compressed, this means that the content in filesystem cache is compressed.
internal cache is the part controlled by MongoDB, which stores recently used data, indexes, etc., and is unzipped.
1) this is actually a knowledge of the principles of the operating system. To load data into memory, MongoDB must first read the original file from disk, then the contents of the file will be entered into filesystem cache. Then you have to convert the contents of the file to a format that can be directly used by WiredTiger, that is, decompress and decrypt, and then the content will go into internal cache. So be sure to say that in order, the content in, internal cache must come from filesystem cache, which is loaded first.
2) internal cache is the process memory, filesystem cache is the operating system cache. The latter will be expelled from memory by the LRU algorithm at some point. If it is read again, it will be loaded from disk. However, the former is also likely to be expelled from memory, because the data capacity may be larger than the cache, so it is to retain the needed content and release the temporarily unused parts. The same here is LRU.
3) internal cache uncompressed, filesystem cache compression.

some additional questions to pay attention to:

  1. indexes are compressed in both internal cache and filesystem cache, and the keys of the index are compressed.
  2. the impact of filesystem cache on performance is also critical, so don't ignore its role.

internal cache you can understand as the memory used by the program. Filesystem cache is understood as the file system caching mechanism of the operating system.

in mongo's WiredTiger caching mechanism. If not configured, he will default to use 50% of your system memory for indexing and data caching.
if you have 2 gigabytes of memory, 1 gigabyte of memory will be used for caching.
if your machine memory is relatively small, less than 512m, it uses 256m memory for caching.

the caching of the file system is at the kernel level. You open a file and read it. Shut it down. The system will do some caching according to your usage. When you close this file, the operating system may not release the data from physical memory. It will be faster for you to open and read this file again than to open it for the first time.

whether mongo's cache has been compressed has not been studied.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb6b1d-25f1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb6b1d-25f1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?