Are you experiencing high queues or slow response times in your MongoDB database? Well then, you may have a deeper issues within your database… a high MongoDB Lock Percentage. MongoDB can be a large and complicated database to manage and maintain, which means you will probably have multiple team members accessing and working on data at the same time. MongoDB employs a multi-granular lock system that allows users to concurrently work in the database and view the same data without making conflicting modifications. This Multi-granular locking system locks MongoDB and stops users from writing on it, when someone else is reading or writing, and vice-versa. However it does not lock the database when two or more users are reading simultaneously. MongoDB tracks how often your database is locked with a “Lock Percentage” metric. This percentage is calculated on two separate levels, “database” and “global”. On the “database” level, MongoDB will lock two concurrent users from working on the same database, but will not lock two users on separate databases unless there is a global rule put in place to lock one system when another related one is being used.
If your database is a read-only system, where most users won’t be modifying data on a regular basis, then you should expect a low MongoDB lock percentage, somewhere around 10%. A write database may have an average lock percentage of around 20% but can even exceed 60%. Even in a write-heavy database environment where you often have multiple users working on the data concurrently, you will still want to keep your lock percentage as feasibly low as possible.
A high lock percentage may be the root cause of other issues that you are experiencing in your MongoDB database. When you have a high locking percentage, you may experience slower response and application call times, high queues, increased replication lag, high CPU usage, and even failures. To ensure that none of these issues occur and you minimize your MongoDB lock percentage, we recommend that you set up a monitoring system, such as Google Stackdriver or New Relic, to make sure the lock percentage does not exceed your set limits. To ensure your lock percentage is within the optimal threshold, you may also want to set up alerts to help monitor other key performance indicators with metrics such as: write tickets, available read and write tickets, intent exclusive lock times, and many more. Monitoring these metrics should help you stay on top of everything, and understand why your MongoDB lock percentage may be so high.
BindPlane can stream MongoDB metrics and logs to your data monitoring service of choice, and if you already use Google Stackdriver you can use BindPlane for no extra cost. Read this blog to learn how to configure and deploy MongoDB within BindPlane so you can begin monitoring your MongoDB lock percentage and other KPIs.