Replication: Automatically reassign high volume reads to secondary

76 views
Skip to first unread message

confused

unread,
Oct 26, 2011, 5:55:40 PM10/26/11
to mongodb-user
We are using MongoDB for the first time in our shop. I am doing
research on replication. That is, if there are high volume of reads
on the primary, does MongoDB automatically reassign some of the reads
to the secondaries. Could someone please be kind enough to explain.

Thank you so much!

Eliot Horowitz

unread,
Oct 27, 2011, 12:41:38 AM10/27/11
to mongod...@googlegroups.com
Nothing automatically.
By default all reads hit primary.

For any given query you can tell the driver reading from a secondary is ok.

> --
> 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.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Tiffany

unread,
Oct 27, 2011, 6:42:08 PM10/27/11
to mongod...@googlegroups.com
Hello:
 
We direct all reads/writes to the primary.  However, we hope MongoDB would re-route as much reads to the secondary as possible.  If we set slaveOk(), will all the reads be directed to the secondary, or do we need to manually direct them to the secondary?  Please clarify!
 
Thank you very much for your help!

Timothy Hawkins

unread,
Oct 27, 2011, 7:48:27 PM10/27/11
to mongod...@googlegroups.com, mongod...@googlegroups.com
If you are using php, then this works fine as long as you ate using a php driver 1.1.4 , this seemed to stop working on any php driver greater than that. We had to downgrade all of our production systems to this version to make it work. 

Sent from my iPad

Tiffany

unread,
Oct 27, 2011, 8:41:21 PM10/27/11
to mongod...@googlegroups.com
Hello:

We are using Java. 

If we set slaveOk(), then the reads would be distributed to the secondary automatically, as we had hoped.  However, none of the writes would go through.  If we turn of slaveOk(), then all reads and writes would be directed towards the primary, then there was no problem. 

We would like to know if MongoDB would automatically re-direct all reads to the secondary and the writes to the primary.  Of course, we could manually set all reads to the secondary and the writes to the primary explicitly in Java, which would be very messy.  We would like to know if MongoDB has a solution.

Thanks a lot for your help! 

Nat

unread,
Oct 27, 2011, 8:58:52 PM10/27/11
to mongod...@googlegroups.com
With slaveOk on, all writes should still go to primary. If you don't see it working and you don't get any exception, can you turn WriteConcern.SAFE to find out what goes wrong?
From: Tiffany <tiffa...@gmail.com>
Date: Thu, 27 Oct 2011 17:41:21 -0700
Subject: Re: [mongodb-user] Replication: Automatically reassign high volume reads to secondary

Tony Hannan

unread,
Oct 28, 2011, 1:27:21 PM10/28/11
to mongod...@googlegroups.com
Just to reiterate. slaveOk reads always go to a secondary. Non-slaveOk reads always go to the primary. Writes always go to the primary.

Tiffany

unread,
Oct 28, 2011, 1:34:20 PM10/28/11
to mongod...@googlegroups.com
Hello:
 
I have tried setWriteConcern(WriteConcern.SAFE) and slaveOk() together, I was able to write to the primary and propogate to the secondary.  Thanks a lot for your help!
 
However, I was told slaveOk() was deprecated, that I should use setReadPreference(ReadPreference.SECONDARY).  Is this so?
 
Thank you very much for your help!

Tony Hannan

unread,
Oct 28, 2011, 3:37:31 PM10/28/11
to mongod...@googlegroups.com
slaveOK and readPreference=secondary are synonyms.

Scott Hernandez

unread,
Nov 4, 2011, 6:25:56 AM11/4/11
to mongod...@googlegroups.com
In the future a ReadPreference will provide more control over where
reads go, like with tagging support.

slaveOk will continue to work for a while even though it is marked as
deprecated.

Reply all
Reply to author
Forward
0 new messages