翻译或纠错本页面

Map Reduce并发

map-reduce操作包含了几个任务,如从输入集合读取数据、执行 map 函数和 reduce 函数、处理过程中数据写入临时集合、最终的结果输出到集合。

在执行过程中,map-reduce会持有如下几个锁:

  • 读取数据阶段持有一个读锁,每次获取锁后读取100个文档。

  • 每一次写入临时集合时需要持有一个写锁。

  • 如果输出集合不存在,创建输出集合时需要持有一个写锁。

  • If the output collection exists, then the output actions (i.e. merge, replace, reduce) take a write lock. This write lock is global, and blocks all operations on the mongod instance.

注解

The final write lock during post-processing makes the results appear atomically. However, output actions merge and reduce may take minutes to process. For the merge and reduce, the nonAtomic flag is available, which releases the lock between writing each output document. See the db.collection.mapReduce() reference for more information.