Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to read from both members of my Replica Set

Received: by 10.42.89.193 with SMTP id h1mr12795569icm.31.1352786146438;
        Mon, 12 Nov 2012 21:55:46 -0800 (PST)
X-BeenThere: mongodb-csharp@googlegroups.com
Received: by 10.42.68.146 with SMTP id x18ls16038866ici.7.gmail; Mon, 12 Nov
 2012 21:55:45 -0800 (PST)
Received: by 10.50.236.105 with SMTP id ut9mr7783032igc.3.1352786144991;
        Mon, 12 Nov 2012 21:55:44 -0800 (PST)
Received: by 10.50.236.105 with SMTP id ut9mr7783031igc.3.1352786144972;
        Mon, 12 Nov 2012 21:55:44 -0800 (PST)
Return-Path: <woak...@gmail.com>
Received: from mail-ob0-f174.google.com (mail-ob0-f174.google.com [209.85.214.174])
        by gmr-mx.google.com with ESMTPS id s15si1024369igi.1.2012.11.12.21.55.44
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 12 Nov 2012 21:55:44 -0800 (PST)
Received-SPF: pass (google.com: domain of woak...@gmail.com designates 209.85.214.174 as permitted sender) client-ip=209.85.214.174;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of woak...@gmail.com designates 209.85.214.174 as permitted sender) smtp.mail=woak...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-ob0-f174.google.com with SMTP id uo13so7061034obb.19
        for <mongodb-csharp@googlegroups.com>; Mon, 12 Nov 2012 21:55:44 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=VqUyhSLFvtpNuYlXaAeckQ5cw2x8oopzNIJc1dUX8sA=;
        b=MEh2WkBvPxuwxbX4akTL5MmFzMMLnLLDd0kkw5qz8t07GpExK5th7lDgPTkLi2K1LR
         GfWiZiphAWf4BkZT9+IZPrFiovaIAWRrGqluni1FbWfx8PYe9VdOCJv2qK2KvHLd+2B/
         /YcKbRGK4rCjiHiRci2f7km6kA1k7KjmDGOK6q8Kqval+avjMpY/bNSL15jrJG0KuZXL
         0OEaXH1nL6YwdX9bbetp1yGqIoVC4+e/SvQErjiLi9m38SKsPkTRVJBMnm04/JQogrWs
         x5Qr8gLcG+cpWEgp5z4ODhTJnhu6GpwVM8s25jOTaUYmS1fvNDPf37643QWyrye3Vcmk
         cO/Q==
MIME-Version: 1.0
Received: by 10.60.7.6 with SMTP id f6mr16286992oea.138.1352786144633; Mon, 12
 Nov 2012 21:55:44 -0800 (PST)
Received: by 10.60.10.233 with HTTP; Mon, 12 Nov 2012 21:55:44 -0800 (PST)
In-Reply-To: <CAJCJWG3zpm9aQhx2oWbjQTkfmXM-gK6V3N=ZBEuN+iYfvwb...@mail.gmail.com>
References: <b4c07b31-726e-4801-bf3a-e5b30d7a4dda@googlegroups.com>
	<4f91264f-e4e8-4e1e-969e-6ab250aa5291@googlegroups.com>
	<CAJCJWG2YzNR5Hm_k8MnkCmtjmOF2vM1QN4UKvqjk80aayWZ...@mail.gmail.com>
	<e8d40477-9415-4f28-9566-55c412843772@googlegroups.com>
	<CAJCJWG3zpm9aQhx2oWbjQTkfmXM-gK6V3N=ZBEuN+iYfvwb...@mail.gmail.com>
Date: Mon, 12 Nov 2012 21:55:44 -0800
Message-ID: <CAJ6JP+g_13tUnaZtd_igM2Lnpf4VkPoe8hmwopK_hGp8OdU...@mail.gmail.com>
Subject: Re: [mongodb-csharp] Re: How to read from both members of my Replica Set
From: John Woakes <woak...@gmail.com>
To: mongodb-csharp@googlegroups.com
Content-Type: multipart/alternative; boundary=e89a8fb2017a9ba3b004ce5a118b

--e89a8fb2017a9ba3b004ce5a118b
Content-Type: text/plain; charset=ISO-8859-1

Hi Robert,

Have you considered creating a setting that would wait if an election is in
progress when trying to issue an update command? It is a pain to have that
period when the replica set is "down" when a wait would be pretty seamless
for the very few times this happens. We are running in Azure so our servers
do go down. Replica sets should protect us from this with out failing
writes if possible.

John.

On Wed, Nov 7, 2012 at 11:02 AM, Robert Stam <rob...@10gen.com> wrote:

> You only have one server on the connection string?
>
> If so, that implies a direct connection without using replica set
> discovery behavior.
>
> You can either use a more complete seed list (minimum of two) or add
> "connect=replicaSet" or "replica=xyz", where xyz is the name of your
> replica set, to get replica set behavior.
>
> Even with replica set behavior, there are a couple of things to keep in
> mind. First is that the driver does not guarantee you won't see any
> exceptions, just that it will switch over to the new primary as soon as it
> can. During the period that the election is taking place (and there is no
> primary) you are pretty much guaranteed to get exceptions. Second, the
> smoothness with which the driver tracks changes in the state of the replica
> set members has been improving, so yet another reason that you should
> upgrade from 1.4.2 when you can.
>
> On Wed, Nov 7, 2012 at 1:56 PM, Tom DeMille <t...@boomtownroi.com> wrote:
>
>> Thanks Robert.
>>
>> A moment ago my new secondary switched to Primary (because I configured
>> it incorrectly with priority 2).  When this happened my web applications
>> started failing with "Server is not a primary and SlaveOk is false."
>> errors.
>>
>> I understand that in one respect, in that we are NOT using slaveOK.  But
>> what I don't understand is why my web application, via the c# driver,
>>  didn't just 'find' the new primary via discovery from Mongo.
>>
>> Does the c# driver cache the replication stuff?  Would I need to do an
>> IISRESET or blow away my application pools in order to get the replication
>> information that I just recently setup?  My understanding has been that the
>> c# driver should have known about the 3 servers in my cluster, even though
>> I didn't specifically add the new IP to my connection string, and
>> automatically have found the new primary.
>>
>>
>> Here is my current (obscured) connect string
>> : mongodb://xxx.xxx.xxx.xxx/?maxpoolsize=200;waitqueuemultiple=5.0;waitqueuetimeout=120s
>>
>> Tom
>>
>>
>>
>>
>> On Wednesday, November 7, 2012 12:16:21 PM UTC-5, Robert Stam wrote:
>>
>>> In version 1.4.2 the only setting available to you is slaveOk=true or
>>> false.
>>>
>>> If you set slaveOk=true your reads will go to the secondary. If you set
>>> slaveOk=false your reads will go to the primary. There is no way to get the
>>> driver to load balance between them. You could of course do the load
>>> balancing yourself by alternately setting slaveOk to false or true to
>>> distribute the reads.
>>>
>>> Once you upgrade to 1.6.1 you and use the new ReadPreference setting,
>>> which replaces slaveOk and has more values:
>>>
>>> Primary (equivalent to slaveOk=false)
>>> PrimaryPreferred
>>> Secondary
>>> SecondaryPreferred (equivalent to slaveOk=true)
>>> Nearest
>>>
>>> Seems like Nearest would do what you want, distributing the reads
>>> between the primary and secondary. Note that Nearest load balances evenly
>>> (in other words, it doesn't measure the load, it just evenly distributes
>>> the reads among all eligible servers).
>>>
>>> On Wed, Nov 7, 2012 at 11:56 AM, Tom DeMille <t...@boomtownroi.com>wrote:
>>>
>>>> Check that, we can't upgrade the driver right now, using 1.4.2
>>>>
>>>>
>>>>
>>>> On Wednesday, November 7, 2012 11:54:36 AM UTC-5, Tom DeMille wrote:
>>>>>
>>>>> Have a 3 node replica set, where one node is an Arbiter.  Thus at any
>>>>> one time I have a primary and secondary server.  I would like to allow my
>>>>> application to read from either one, in fact I would love to 'load balance'
>>>>> the load somehow.
>>>>>
>>>>> Whats the best way to achieve this?    If the primary is running
>>>>> 'slow' will the driver automatically read from the secondary, thus
>>>>> achieving a true 'load' based balance?
>>>>>
>>>>> What would the c# code/connection strings look like to accomplish
>>>>> this.  It seems this has changed over the past year and 1/2 and I want to
>>>>> check in for the latest greatest best practices.
>>>>>
>>>>> I'm using 2.2.1 Mongo.
>>>>>
>>>>> I will be updating c# driver to latest version.
>>>>>
>>>>
>>>
>

--e89a8fb2017a9ba3b004ce5a118b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Robert,<br><br>Have you considered creating a setting that would wait if=
 an election is in progress when trying to issue an update command? It is a=
 pain to have that period when the replica set is &quot;down&quot; when a w=
ait would be pretty seamless for the very few times this happens. We are ru=
nning in Azure so our servers do go down. Replica sets should protect us fr=
om this with out failing writes if possible.<br>
<br>John.<br><br><div class=3D"gmail_quote">On Wed, Nov 7, 2012 at 11:02 AM=
, Robert Stam <span dir=3D"ltr">&lt;<a href=3D"mailto:rob...@10gen.com" tar=
get=3D"_blank">rob...@10gen.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">
You only have one server on the connection string?<div><br></div><div>If so=
, that implies a direct connection without using replica set discovery beha=
vior.</div><div><br></div><div>You can either use a more complete seed list=
 (minimum of two) or add &quot;connect=3DreplicaSet&quot; or &quot;replica=
=3Dxyz&quot;, where xyz is the name of your replica set, to get replica set=
 behavior.</div>

<div><br></div><div>Even with replica set behavior, there are a couple of t=
hings to keep in mind. First is that the driver does not guarantee you won&=
#39;t see any exceptions, just that it will switch over to the new primary =
as soon as it can. During the period that the election is taking place (and=
 there is no primary) you are pretty much guaranteed to get exceptions. Sec=
ond, the smoothness with which the driver tracks changes in the state of th=
e replica set members has been improving, so yet another reason that you sh=
ould upgrade from 1.4.2 when you can.<br>

<br><div class=3D"gmail_quote">On Wed, Nov 7, 2012 at 1:56 PM, Tom DeMille =
<span dir=3D"ltr">&lt;<a href=3D"mailto:t...@boomtownroi.com" target=3D"_bla=
nk">t...@boomtownroi.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail=
_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:=
1ex">

Thanks Robert. =A0<div><br></div><div>A moment ago my new secondary switche=
d to Primary (because I configured it incorrectly with priority 2). =A0When=
 this happened my web applications started=A0failing with &quot;<span style=
=3D"font-family:arial,sans-serif;font-size:13.333333969116211px">Server is =
not a primary and SlaveOk is false.&quot; errors.</span></div>

<div><span style=3D"font-family:arial,sans-serif;font-size:13.3333339691162=
11px"><br></span></div><div><span style=3D"font-family:arial,sans-serif;fon=
t-size:13.333333969116211px">I understand that in one respect, in that we a=
re NOT using slaveOK. =A0But what I don&#39;t understand is why my web appl=
ication, via the c# driver, =A0didn&#39;t just &#39;find&#39; the new prima=
ry via discovery from Mongo. =A0</span></div>

<div><span style=3D"font-family:arial,sans-serif;font-size:13.3333339691162=
11px"><br></span></div><div><span style=3D"font-family:arial,sans-serif;fon=
t-size:13.333333969116211px">Does the c# driver cache the replication stuff=
? =A0Would I need to do an IISRESET or blow away my application pools in or=
der to get the replication information that I just recently setup? =A0My un=
derstanding has been that the c# driver should have known about the 3 serve=
rs in my cluster, even though I didn&#39;t specifically add the new IP to m=
y connection string, and automatically have found the new primary.</span></=
div>

<div><div><font face=3D"arial, sans-serif"><br></font></div><div><font face=
=3D"arial, sans-serif"><br></font></div><div><font face=3D"arial, sans-seri=
f">Here is my current (obscured) connect string :=A0mongodb://xxx.xxx.xxx.x=
xx/?maxpoolsize=3D200;waitqueuemultiple=3D5.0;waitqueuetimeout=3D120s</font=
></div>

<span><font color=3D"#888888"><div><font face=3D"arial, sans-serif"><br></f=
ont></div><div><font face=3D"arial, sans-serif">Tom</font></div><div><font =
face=3D"arial, sans-serif"><br></font></div><div><font face=3D"arial, sans-=
serif"><br>

</font></div><div><font face=3D"arial, sans-serif"><br></font></div></font>=
</span><div><div><font face=3D"arial, sans-serif"><br></font>On Wednesday, =
November 7, 2012 12:16:21 PM UTC-5, Robert Stam wrote:</div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
 solid;padding-left:1ex">

<div>In version 1.4.2 the only setting available to you is slaveOk=3Dtrue o=
r false.<div><br></div><div>If you set slaveOk=3Dtrue your reads will go to=
 the secondary. If you set slaveOk=3Dfalse your reads will go to the primar=
y. There is no way to get the driver to load balance between them. You coul=
d of course do the load balancing yourself by alternately setting slaveOk t=
o false or true to distribute the reads.</div>


<div><br></div><div>Once you upgrade to 1.6.1 you and use the new ReadPrefe=
rence setting, which replaces slaveOk and has more values:</div><div><br></=
div><div><font face=3D"courier new, monospace">Primary (equivalent to slave=
Ok=3Dfalse)</font></div>


<div><font face=3D"courier new, monospace">PrimaryPreferred</font></div><di=
v><font face=3D"courier new, monospace">Secondary</font></div><div><font fa=
ce=3D"courier new, monospace">SecondaryPreferred (equivalent to slaveOk=3Dt=
rue)</font></div>


<div><font face=3D"courier new, monospace">Nearest</font></div><div><br></d=
iv><div>Seems like Nearest would do what you want, distributing the reads b=
etween the primary and secondary. Note that Nearest load balances evenly (i=
n other words, it doesn&#39;t measure the load, it just evenly distributes =
the reads among all eligible servers).</div>


</div><div><div><br><div class=3D"gmail_quote">On Wed, Nov 7, 2012 at 11:56=
 AM, Tom DeMille <span dir=3D"ltr">&lt;<a>t...@boomtownroi.com</a>&gt;</spa=
n> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex">


Check that, we can&#39;t upgrade the driver right now, using 1.4.2<div><div=
><div><br></div><div><br><br>On Wednesday, November 7, 2012 11:54:36 AM UTC=
-5, Tom DeMille wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;m=
argin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">


Have a 3 node replica set, where one node is an Arbiter. =A0Thus at any one=
 time I have a primary and secondary server. =A0I would like to allow my ap=
plication to read from either one, in fact I would love to &#39;load balanc=
e&#39; the load somehow.<div>


<br></div><div>Whats the best way to achieve this? =A0 =A0If the primary is=
 running &#39;slow&#39; will the driver automatically read from the seconda=
ry, thus achieving a true &#39;load&#39; based balance?</div><div><br></div=
>


<div>What would the c# code/connection strings look like to accomplish this=
. =A0It seems this has changed over the past year and 1/2 and I want to che=
ck in for the latest greatest best practices.</div><div><br></div><div>I&#3=
9;m using 2.2.1 Mongo.</div>


<div><br></div><div>I will be updating c# driver to latest version.</div></=
blockquote></div></div></div></blockquote></div><br></div>
</div></blockquote></div></div></blockquote></div><br></div>
</blockquote></div><br>

--e89a8fb2017a9ba3b004ce5a118b--