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

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.

主站蜘蛛池模板: 同江市| 城口县| 南阳市| 洪洞县| 沂水县| 仁化县| 香河县| 盱眙县| 天台县| 宜都市| 揭阳市| 仁寿县| 白玉县| 得荣县| 宣威市| 察隅县| 亚东县| 苍溪县| 禹城市| 阿拉善左旗| 石台县| 石家庄市| 和平区| 宣武区| 赤水市| 祁东县| 台安县| 登封市| 稷山县| 华阴市| 绥芬河市| 黔江区| 交城县| 长岛县| 开平市| 维西| 南召县| 堆龙德庆县| 枣阳市| 中山市| 邵阳县|