官术网_书友最值得收藏!

  • Mastering MongoDB 3.x
  • Alex Giamas
  • 257字
  • 2021-08-20 10:10:56

MapReduce concurrency

MapReduce operations will place several short-lived locks that should not affect operations. However, at the end of the reduce phase, if we are outputting data to an existing collection, then output actions such as merge, reduce, and replace will take an exclusive global write lock for the whole server, blocking all other writes in the db instance. If we want to avoid that we should invoke MapReduce in the following way:

> db.collection.mapReduce(
mapper,
reducer,
{
out: { merge/reduce: bookOrders, nonAtomic: true }
})

We can apply nonAtomic only to merge or reduce actions. replace will just replace the contents of documents in bookOrders, which would not take much time anyway.

With the merge action, the new result is merged with the existing result if the output collection already exists. If an existing document has the same key as the new result, then it will overwrite that existing document.

With the reduce action, the new result is processed together with the existing result if the output collection already exists. If an existing document has the same key as the new result, it will apply the reduce function to both the new and the existing documents and overwrite the existing document with the result.

Although MapReduce has been present since the early versions of MongoDB, it hasn't evolved as much as the rest of the database, resulting in its usage being less than that of specialized MapReduce frameworks such as Hadoop, which we will learn more about in Chapter 9, Harnessing Big Data with MongoDB.

主站蜘蛛池模板: 福海县| 闻喜县| 黄平县| 顺平县| 道真| 五华县| 克东县| 黔南| 阜阳市| 广南县| 台州市| 资阳市| 广平县| 红安县| 三都| 平潭县| 屏东县| 绍兴县| 三明市| 田阳县| 香港 | 中西区| 和田市| 定边县| 丽江市| 贵州省| 临夏县| 新野县| 云浮市| 皋兰县| 贡觉县| 青岛市| 宁波市| 子长县| 云浮市| 新绛县| 合水县| 叙永县| 敖汉旗| 邻水| 浦城县|