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

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.

主站蜘蛛池模板: 苍梧县| 加查县| 罗田县| 乌海市| 庆安县| 伊川县| 剑阁县| 肇庆市| 平武县| 治县。| 兴宁市| 洪湖市| 泗阳县| 福建省| 乌海市| 神木县| 麟游县| 攀枝花市| 峨眉山市| 屏山县| 新宁县| 东乌珠穆沁旗| 饶河县| 江孜县| 延长县| 武宁县| 黔东| 蚌埠市| 萨迦县| 横山县| 怀来县| 沈丘县| 大姚县| 阿合奇县| 鸡西市| 凤城市| 涞源县| 浦东新区| 肥城市| 班玛县| 子长县|