MapReduce on SECONDARY in a ReplicaSet

444 views
Skip to first unread message

Mark Hansen

unread,
Sep 29, 2012, 7:50:18 PM9/29/12
to mongod...@googlegroups.com
Running 2.2.0 3 box replicaset with one primary.

PRIMARY is write-intensive and loads data all day long from various sources.

The 2 SECONDARY server are supposed to support the read-only end of the application.  However, the "reads" involve lots of map-reduces that produce large results we store in temporary collections for sorting, etc.

All was working OK in dev when we had one machine.  Now, trying to go to production we just learned that we can't write the map-reduce results to a temporary collection on the SECONDARY.  (per http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Outputoptions).  When we try (C# driver), we get Command 'mapreduce' failed: not master (response: { "errmsg" : "not master", "ok" : 0.0 }

Can anyone suggest a solution?

Stephen Steneker

unread,
Sep 30, 2012, 9:34:10 PM9/30/12
to mongod...@googlegroups.com
Hi Mark,

If you want to run Map/Reduce on a secondary you will need to use SlaveOK and the "inline" output option, which does not require write access.  Note that inline results are limited to the maximum document size (currently 16Mb).  To save those results to a collection you would still have to commit via the primary, from your C# code.

If you are using the C# 1.6 driver or newer, you can use the additional Read Preferences supported by MongoDB 2.2:

Depending on the sort of processing you are doing, you may be able to use a query filter to create a more efficient incremental Map/Reduce:
 http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-IncrementalMapreduce

Another option for read-only queries in MongoDB 2.2 is the new Aggregation Framework:
 http://docs.mongodb.org/manual/applications/aggregation/

Cheers,
Stephen

Scott Hernandez

unread,
Sep 30, 2012, 10:23:10 PM9/30/12
to mongod...@googlegroups.com
Mark, I think you will want to watch this feature request:
https://jira.mongodb.org/browse/SERVER-4264

There are a few others that may help you in the future as well. Take a
look in Jira, or add a new one.
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

Mark Hansen

unread,
Oct 1, 2012, 9:46:04 AM10/1/12
to mongod...@googlegroups.com
Stephen, thanks for the tips.  We are running 2.2.0 and also using the 1.6 C# drivers.  I'm trying to avoid hacking the map-reduce code to manage performance and/or the 16MB limitation; but may have no choice.  Aggregation FW looks good, but seems like it also has a 16MB in-line limitation - is this true?

Mark Hansen

unread,
Oct 1, 2012, 9:50:49 AM10/1/12
to mongod...@googlegroups.com
Yes, I just gave that a +1.  Thanks for pointing it out.

Stephen Steneker

unread,
Oct 1, 2012, 8:31:20 PM10/1/12
to mongod...@googlegroups.com
Stephen, thanks for the tips.  We are running 2.2.0 and also using the 1.6 C# drivers.  I'm trying to avoid hacking the map-reduce code to manage performance and/or the 16MB limitation; but may have no choice.  Aggregation FW looks good, but seems like it also has a 16MB in-line limitation - is this true?

Hi Mark,

Yes .. inline results for both Map/Reduce and Aggregation Framework are limited to the current max document size (16MB as at MongoDB 2.2).

Cheers,
Stephen
Reply all
Reply to author
Forward
0 new messages