Skip to content

Commit

Permalink
NCBC-146: Randomly select a node to handle view requests
Browse files Browse the repository at this point in the history
Change-Id: I12824c4ff63a1fd3b6f7a82d20c12d11c36b43e8
Reviewed-on: http://review.couchbase.org/21895
Reviewed-by: Jasdeep Jaitla <jasdeep@couchbase.com>
Tested-by: John C. Zablocki <john@couchbase.com>
  • Loading branch information
jzablocki authored and John C. Zablocki committed Nov 21, 2012
1 parent 1d46994 commit 8d83bea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Couchbase/CouchbaseClient.cs
Expand Up @@ -736,8 +736,10 @@ private void getViewSetup(ref string designName, ref string viewName)

IHttpClient IHttpClientLocator.Locate(string designDocument)
{
// find the node hosting this design document
var node = this.Pool.Locate(designDocument) as CouchbaseNode;
//pick a node at random to avoid overloading a single node with view requests
var nodes = this.Pool.GetWorkingNodes().ToArray();
var idx = new Random(Environment.TickCount).Next(nodes.Length);
var node = nodes[idx] as CouchbaseNode;

// return null if the node is dead
return (node != null && node.IsAlive)
Expand Down

0 comments on commit 8d83bea

Please sign in to comment.