Distributing reads between primary and secondary servers

118 views
Skip to first unread message

Manasi Sahasrabudhe

unread,
Oct 15, 2012, 12:58:26 PM10/15/12
to mongod...@googlegroups.com
hi,
I recently started using mongodb. I am using mongo php client 1.2.10 and I have 1 primary and 2 secondaries setup for mongodb servers.
Here are my questions,
1. How should I configure distributing reads between primary and secondary. I read about readPreferences and could I find relevant mode where I my reads will get processed in 2:1 (secondary:primary ratio).
I came across these links,
but I am not sure setting it manually (using slaveOkay) is a correct way or that's deprecared.
2. If I select readPreference as "SecondaryPreffered", how one of the secondary server is selected? in round robin way? or?
3. How to find out which one of the 3 mongo servers my request is being read from? I tried to tail mongodb logs but could not figure out.

Any pointers/thoughts will be much appreciated.
Thanks,
-Manasi

Dwight Merriman

unread,
Oct 15, 2012, 1:07:34 PM10/15/12
to mongod...@googlegroups.com
 
3. How to find out which one of the 3 mongo servers my request is being read from? I tried to tail mongodb logs but could not figure out.

you can run either the hostInfo command or serverStatus or replSetGetStatus.  hostInfo is probably easiest. in replSetGetStatus you will see self:true for the server you are talking to

e.g. shell syntax: 

> db.hostInfo()
> // or:
> use admin
> db.runCommand("hostInfo")


Dwight Merriman

unread,
Oct 15, 2012, 1:23:54 PM10/15/12
to mongod...@googlegroups.com
from the docs best times to query secondaries are the following (below).  i wouldn't automatically drop into querying secondaries just for read scale.  be sure if you do your query use case is ok with eventual consistent read semantics.
  • Running systems operations that do not affect the front-end application, operations such as backups and reports.
  • Providing low-latency queries for geographically distributed deployments. If one secondary is closer to an application server than the primary, you may see better performance for that application if you use secondary reads.
  • Providing graceful degradation in failover situations where a set has no primary for 10 seconds or more. In this use case, you should give the application the primaryPreferredread preference, which prevents the application from performing reads if the set has no primary.
but I am not sure setting it manually (using slaveOkay) is a correct way or that's deprecared.
2. If I select readPreference as "SecondaryPreffered", how one of the secondary server is selected? in round robin way? or?
 
i think randomly but i'm not positive.

by the way, consider just sending queries to the primary.  

Jason Rassi

unread,
Oct 15, 2012, 4:52:33 PM10/15/12
to mongod...@googlegroups.com
> i think randomly but i'm not positive.

Yes, a random secondary is chosen.  See http://docs.mongodb.org/manual/applications/replication/#replica-set-read-preference-behavior-member-selection for details on how the selection is made (and also the "request association" section just above).
Reply all
Reply to author
Forward
0 new messages