Hello All,
How to get the buffer/cache pool hit ratio in MongoDB as we do it in DB2 and MySQL?
What is the good ratio of buffer/cache hit ratio for best performance?
Thank you in advance.
Hello All,
How to get the buffer/cache pool hit ratio in MongoDB as we do it in DB2 and MySQL?
What is the good ratio of buffer/cache hit ratio for best performance?
Thank you in advance.
Hey, welcome to the MongoDB community!
In MongoDB, the buffer/cache hit rate refers to the efficiency with which the in-memory data cache (WiredTiger in the case of the default storage engine) is utilized. A high hit rate typically indicates that most read operations are being served from the in-memory cache, which is faster than reading from disk.
To get statistics on cache performance in MongoDB when using the WiredTiger storage engine, you can use the serverStatus command:
db.serverStatus( { "wiredTiger.cache": 1 } )
Within the wiredTiger.cache section, you’ll find various cache-related statistics. Statistics of interest include:
bytes currently in the cachetracked dirty bytes in the cachebytes read into cachebytes written from cacheThe hit rate can be approximated from these statistics, but MongoDB does not provide a direct “cache hit rate” like some other databases.
In general, a cache hit rate above 95% is considered good for most workloads. This means that 95% or more of the read operations are being served from the cache instead of going to disk. However, the exact value considered “good” may vary based on the nature of your workload and your system’s configuration.
If the cache hit rate is consistently below 95%, it may be an indication that:
In these cases, you might consider:
Hi, thanks for the explanation Samuel_84194. However, it’s unclear to me how we can calculate the hit ratio using these statistics. What would be the logic used?
bytes currently in the cachetracked dirty bytes in the cachebytes read into cachebytes written from cacheBest Regards,
Rodrigo Lima.
Hello Rodrigo.
In the db.serverStatus().wiredTiger.cache command you will see some metrics. To perform the calculation we use the pages read in the cache (Pages Read Into Cache) and the total number of requests to the cache (Total Pager Requests).
The calculation is done as:
Cache hit rate = (1 - (Pages read from cache / Total requests)) * 100%
E.g
pages read into cache: 30
pages requested from the cache: 218
Cache hit rate = (1 - (30 / 218)) * 100%
Cache hit rate = 86.24%
Hi, Samuel. Thanks for the help. ![]()