- 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.
- 大數(shù)據(jù)戰(zhàn)爭(zhēng):人工智能時(shí)代不能不說(shuō)的事
- Mastering VMware vSphere 6.5
- Expert AWS Development
- JMAG電機(jī)電磁仿真分析與實(shí)例解析
- 工業(yè)機(jī)器人現(xiàn)場(chǎng)編程(FANUC)
- Windows 7寶典
- Cloudera Administration Handbook
- 網(wǎng)絡(luò)布線與小型局域網(wǎng)搭建
- 悟透AutoCAD 2009案例自學(xué)手冊(cè)
- Word 2007,Excel 2007辦公應(yīng)用融會(huì)貫通
- 單片機(jī)技術(shù)項(xiàng)目化原理與實(shí)訓(xùn)
- IBM? SmartCloud? Essentials
- 傳感技術(shù)基礎(chǔ)與技能實(shí)訓(xùn)
- fastText Quick Start Guide
- 人工智能產(chǎn)品經(jīng)理:從零開(kāi)始玩轉(zhuǎn)AI產(chǎn)品