MongoDB – Can Read Operations Cause Write Locks?

mongodb

I have a MongoDB database with ~100GB data size. I ran a test with 300 threads and a total 10,000 'read' queries. I notice on the MMS lock% it is showing 0.6 ~ 1% of write lock. My question is, the queries are purely 'read', why is it showing write lock?

Best Answer

First off, to correct the comment: the profiler does not write to the local database, it writes to whatever database you are profiling in the system.profile collection. So if you were reading from database foo and had profiling turned on, the collection would be foo.system.profile. You could turn on profiling for the local database, and hence have the profiler write there of course, but it is not a default of any kind.

Then, if you have the profiler enabled, regardless of where it writes too, all writes require a write lock whether they are to the system.profile collection or anywhere else. Just because it is getting input internally does not exclude the system.profile collection from following the same rules as any other collection on a database.

If you turn the profiler off I would expect the lock to disappear. There may still be the occasional blip in the global lock percentage in the stats but that is essentially just background noise.