[ 
https://issues.apache.org/jira/browse/GEODE-4147?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16324714#comment-16324714
 ] 

ASF GitHub Bot commented on GEODE-4147:
---------------------------------------

PivotalSarge closed pull request #1237: GEODE-4147: Add variability to client 
rebalance logic
URL: https://github.com/apache/geode/pull/1237
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java 
b/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
index c266b8bb3a..897029fb52 100644
--- 
a/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
+++ 
b/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
@@ -25,6 +25,7 @@
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
+import java.util.SplittableRandom;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
@@ -159,6 +160,26 @@ public static PoolImpl create(PoolManagerImpl pm, String 
name, Pool attributes,
     return pool;
   }
 
+  /**
+   * Adds an arbitrary variance to a positive temporal interval. Where 
possible, 10% of the interval
+   * is added or subtracted from the interval. Otherwise, 1 is added or 
subtracted from the
+   * interval. For all positive intervals, the returned value will 
<bold>not</bold> equal the
+   * supplied interval.
+   *
+   * @param interval Positive temporal interval.
+   * @return Adjusted interval including the variance for positive intervals; 
the unmodified
+   *         interval for non-positive intervals.
+   */
+  static int addVarianceToInterval(int interval) {
+    if (1 <= interval) {
+      final SplittableRandom random = new SplittableRandom();
+      final int variance = (interval < 10) ? 1 : random.nextInt(interval / 10);
+      final int sign = random.nextBoolean() ? 1 : -1;
+      return interval + (sign * variance);
+    }
+    return interval;
+  }
+
   public boolean isUsedByGateway() {
     return usedByGateway;
   }
@@ -186,7 +207,7 @@ protected PoolImpl(PoolManagerImpl pm, String name, Pool 
attributes,
     this.name = name;
     this.socketConnectTimeout = attributes.getSocketConnectTimeout();
     this.freeConnectionTimeout = attributes.getFreeConnectionTimeout();
-    this.loadConditioningInterval = attributes.getLoadConditioningInterval();
+    this.loadConditioningInterval = 
addVarianceToInterval(attributes.getLoadConditioningInterval());
     this.socketBufferSize = attributes.getSocketBufferSize();
     this.threadLocalConnections = attributes.getThreadLocalConnections();
     this.readTimeout = attributes.getReadTimeout();
diff --git 
a/geode-core/src/test/java/org/apache/geode/cache/client/internal/ConnectionPoolImplJUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/cache/client/internal/ConnectionPoolImplJUnitTest.java
index da87243fc1..c227320a95 100644
--- 
a/geode-core/src/test/java/org/apache/geode/cache/client/internal/ConnectionPoolImplJUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/cache/client/internal/ConnectionPoolImplJUnitTest.java
@@ -16,7 +16,10 @@
 
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.net.InetSocketAddress;
 import java.net.SocketTimeoutException;
@@ -267,4 +270,12 @@ public boolean useThreadLocalConnection() {
     assertEquals(location1, 
pool.executeOnQueuesAndReturnPrimaryResult(testOp));
   }
 
+  @Test
+  public void testAddVarianceToInterval() {
+    assertThat(PoolImpl.addVarianceToInterval(0)).as("Zero gets zero 
variance").isEqualTo(0);
+    assertThat(PoolImpl.addVarianceToInterval(300000)).as("Large value gets 
+/-10% variance")
+        
.isNotEqualTo(300000).isGreaterThanOrEqualTo(270000).isLessThanOrEqualTo(330000);
+    assertThat(PoolImpl.addVarianceToInterval(9)).as("Small value gets +/-1 
variance")
+        .isNotEqualTo(9).isGreaterThanOrEqualTo(8).isLessThanOrEqualTo(10);
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add variability to client rebalance logic
> -----------------------------------------
>
>                 Key: GEODE-4147
>                 URL: https://issues.apache.org/jira/browse/GEODE-4147
>             Project: Geode
>          Issue Type: Improvement
>          Components: client/server, locator
>            Reporter: Galen O'Sullivan
>            Assignee: Michael Dodge
>              Labels: pull-request-available
>
> Clients periodically check with the locator to see if they would be better 
> connected to another server, for load balancing purposes 
> ({{ClientReplacementRequest}}). Currently the delay is always the same, which 
> can cause clients to flip flop between servers that the locator thinks are 
> more or less loaded. Adding variability to the delay will help reduce the 
> amount of coordinated hammering.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to