Behavior of Java Driver in a geographically disperse replica set.

12 views
Skip to first unread message

Riyad

unread,
Oct 25, 2011, 6:59:22 PM10/25/11
to mongod...@googlegroups.com
Example Setup

5 servers located in:
- US West Coast
- US East Coast
- Ireland
- Tokyo
- Australia

All 5 servers are configured in a replica set with US-West as the write master.

Question

Using the Java Driver, consider that a web app on each of those servers (running along side each of the mongo instances) connects to the local mongo instance.

Q1. Can each of those instances issue write commands to their localhost Mongo instances that are transparently (via logic in the driver) sent to the write master in US-West or does every node need to know who the current master is and specifically write to it?

Q2. If the answer to Q1 is "yes, it is automatically decided by the driver", what is the lag time and behavior when the master goes down and a new master is elected? Will the Java Driver attempt the write to the old location, see the error, and query for the new master to retarget or does this require programmer interaction?

I am trying to get some usage insight into the details of a geographically disperse Mongo replica set via the Java Driver. If there are any other interesting details I might be missing (or should know) I'd surely appreciate the pointers.

Thank you.

Riyad

unread,
Oct 25, 2011, 7:12:00 PM10/25/11
to mongod...@googlegroups.com
I see this question suggests that the Mongo drivers will attempt to "find the master" when a write fails, so I believe the answer to Q1 is "yes" in which case I'm curious about the types of latency I can expect for Q2.

For example, is it just an issue of the set electing a new primary and as soon as it does there is no additional latency, or do the drivers have some retry logic that may introduce additional lag into realizing the primary has changed?

From my perspective it looks like all I need to do is catch exceptions on write and retry them, letting the drivers handle figuring out who the new primary is. After 10 tries or something reasonable, I would fail the write completely and report some system error to an admin (e.g. "no primary elected after 1 min" or some such error).

Does this sound correct/sane/good/ok?

Malte Finsterwalder

unread,
Oct 26, 2011, 4:02:31 AM10/26/11
to mongod...@googlegroups.com
To know how long i takes, in your setting to elect a new master, you
can easily create an experiment.
That will show you what to expect.
In our case it usually takes a couple of seconds, until a new primary
is elected.
That's what you should roughly expect.

Greetings,
Malte

Scott Hernandez

unread,
Oct 26, 2011, 4:09:15 AM10/26/11
to mongod...@googlegroups.com
On Wed, Oct 26, 2011 at 9:59 AM, Riyad <rka...@gmail.com> wrote:
> Example Setup
> 5 servers located in:
> - US West Coast
> - US East Coast
> - Ireland
> - Tokyo
> - Australia
> All 5 servers are configured in a replica set with US-West as the write
> master.
> Question
> Using the Java Driver, consider that a web app on each of those servers
> (running along side each of the mongo instances) connects to the local mongo
> instance.
> Q1. Can each of those instances issue write commands to their localhost
> Mongo instances that are transparently (via logic in the driver) sent to the
> write master in US-West or does every node need to know who the current
> master is and specifically write to it?

In replicaset mode (when using the Mongo constructor which takes a
list/array) the driver will keep track of the primary/master and send
writes to that node. There is background thread which is responsible
for keeping the state up to date.

> Q2. If the answer to Q1 is "yes, it is automatically decided by the driver",
> what is the lag time and behavior when the master goes down and a new master
> is elected? Will the Java Driver attempt the write to the old location, see
> the error, and query for the new master to retarget or does this require
> programmer interaction?

Yes, and yes, but no retries will be issued on writes; exceptions will
be raised. Your code will need to handle that.

> I am trying to get some usage insight into the details of a geographically
> disperse Mongo replica set via the Java Driver. If there are any other
> interesting details I might be missing (or should know) I'd surely
> appreciate the pointers.

I think you got most of it. If you do slaveOk reads (soon to be
ReadPreference.PreferSecondary) then reads will go to the local
(closest by ping command timing) replica (non-primary).

> Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/ASxucX5upakJ.
> 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.
>

Reply all
Reply to author
Forward
0 new messages