Regarding Performance of Map & Reduce Function in MongoDB

37 views
Skip to first unread message

ljia...@ucr.edu

unread,
Oct 16, 2017, 12:04:04 AM10/16/17
to mongodb-user
Hello,

I did some evaluations on mongoDB recently. As I evaluated the map & reduce function on a linux server, I found two bottlenecks for this function:
(1) Map & reduce function is much slower than db.count() and db.find(). For example, 239 MB dataset with 2394651 rows cost 28 seconds while db.find() costs only 1.66 seconds.
(2) Indexes on relevant fields doesn’t work for map & reduce, but works for db.count() and db.find(). After indexes have been constructed, map & reduce still costs the same time, while the execution times for db.count() and db.find() are much shorter.
Does anyone know the reason for such phenomenons? Many thanks!


ljia...@ucr.edu

unread,
Oct 16, 2017, 1:55:24 PM10/16/17
to mongodb-user
In addition, even if I removed all operation in reduce function, the execution times are still very long (nearly the same as before). Can anyone make some explanations on that phenomenon? Many thanks!

Wan Bachtiar

unread,
Nov 16, 2017, 10:45:14 PM11/16/17
to mongodb-user

Can anyone make some explanations on that phenomenon?

Hi,
It’s been a while since you posted this question, have you found an answer yet ?

Map-Reduce passes every single document in the collection i.e. 2394651 into the map function.
Not only you have to take account of the iteration time, but the additional time it takes to execute your map function per document.

Unless you have a specific use case that requires Map Reduce, I would recommend to either use find() or Aggregation Pipeline

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages