Ruby Driver - Reading from secondaries

27 views
Skip to first unread message

Matt Parlane

unread,
Apr 24, 2012, 5:41:18 PM4/24/12
to mongod...@googlegroups.com
Hi all...

I have a fairly typical web application that is very read-heavy. I have two MongoDB servers, one primary and one secondary. All writes are w = 2 so there's really no difference between the machines as far as the application is concerned. I want to be able to distribute reads among them evenly, but I can't figure out how to do that with the Ruby driver.

I know I can set :read => :secondary to read from secondary nodes, but I want a percentage to go to the primary as well. Ideally it would be something like :read => :closest to read from the closest machine by ping time, whether it's secondary or primary.

Any ideas?

Thanks,

Matt

Kyle Banker

unread,
Apr 25, 2012, 11:40:46 AM4/25/12
to mongod...@googlegroups.com
The Ruby driver will soon support an option with the same meaning as :read => :any, which will read from the closest member.

Are the machines in the same data center? If you, you might consider dividing up reads based on the database (or collections) being read from. You might also consider randomly choosing:
:read => [:primary, :secondary][rand(2)]

Side question: Do you have arbiter? That's pretty important for failover.

Matt Parlane

unread,
Apr 25, 2012, 3:29:51 PM4/25/12
to mongod...@googlegroups.com
On Thursday, April 26, 2012 3:40:46 AM UTC+12, Kyle Banker wrote:
 
The Ruby driver will soon support an option with the same meaning as :read => :any, which will read from the closest member.

Ok cool, as long as I know it's coming. Is there a JIRA ticket? I couldn't find one.
 
Are the machines in the same data center? If you, you might consider dividing up reads based on the database (or collections) being read from. You might also consider randomly choosing:
:read => [:primary, :secondary][rand(2)]
 
Yes they are, I'll give that a go, thanks.
 
Side question: Do you have arbiter? That's pretty important for failover.
 
Thanks for your concern.  :)  Yup I have an arbiter, I'm not new at MongoDB, just the Ruby driver.

Cheers,

Matt

Matt Parlane

unread,
Apr 29, 2012, 11:35:30 PM4/29/12
to mongod...@googlegroups.com
Sorry to nag, but... anyone? Bueller?

Matt

Kyle Banker

unread,
Apr 30, 2012, 10:51:30 AM4/30/12
to mongod...@googlegroups.com
Just created a ticket for this:

Please add yourself as a watcher, and you'll be notified as progress is made.
Reply all
Reply to author
Forward
0 new messages