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

  • 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.

主站蜘蛛池模板: 永善县| 平和县| 广州市| 佛冈县| 海安县| 清苑县| 米泉市| 安宁市| 岳普湖县| 万全县| 修文县| 土默特左旗| 萍乡市| 高阳县| 锡林浩特市| 祥云县| 普兰店市| 西贡区| 阿城市| 东阿县| 察隅县| 涿州市| 东安县| 文山县| 恩施市| 城固县| 石河子市| 呼伦贝尔市| 柘城县| 儋州市| 新安县| 杭州市| 宁国市| 井陉县| 宣汉县| 泗水县| 五寨县| 库尔勒市| 靖远县| 文昌市| 张北县|