This is an automated email from the ASF dual-hosted git repository.

markusthoemmes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 722fda4  Improve loadbalancer overload behaviour. (#3272)
722fda4 is described below

commit 722fda45a1742ad9dcbe47e18c4462826f80e23d
Author: ningyougang <415622...@qq.com>
AuthorDate: Fri Feb 23 16:14:50 2018 +0800

    Improve loadbalancer overload behaviour. (#3272)
    
    Distributes load randomly (evenly) in an overload situation.
---
 .../whisk/core/loadBalancer/ContainerPoolBalancer.scala     |  7 ++++++-
 .../test/ContainerPoolBalancerObjectTests.scala             | 13 ++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git 
a/core/controller/src/main/scala/whisk/core/loadBalancer/ContainerPoolBalancer.scala
 
b/core/controller/src/main/scala/whisk/core/loadBalancer/ContainerPoolBalancer.scala
index 193ed8d..a5327b0 100644
--- 
a/core/controller/src/main/scala/whisk/core/loadBalancer/ContainerPoolBalancer.scala
+++ 
b/core/controller/src/main/scala/whisk/core/loadBalancer/ContainerPoolBalancer.scala
@@ -18,6 +18,7 @@
 package whisk.core.loadBalancer
 
 import java.nio.charset.StandardCharsets
+import java.util.concurrent.ThreadLocalRandom
 
 import akka.actor.{ActorSystem, Props}
 import akka.cluster.Cluster
@@ -343,7 +344,11 @@ object ContainerPoolBalancer extends LoadBalancerProvider {
         .find(_._3 < invokerBusyThreshold)
         .orElse(invokerProgression.find(_._3 < invokerBusyThreshold * 2))
         .orElse(invokerProgression.find(_._3 < invokerBusyThreshold * 3))
-        .orElse(invokerProgression.headOption)
+        .orElse(
+          if (invokerProgression.isEmpty)
+            None
+          else
+            
Some(invokerProgression(ThreadLocalRandom.current().nextInt(invokerProgression.size))))
         .map(_._1)
     } else None
   }
diff --git 
a/tests/src/test/scala/whisk/core/loadBalancer/test/ContainerPoolBalancerObjectTests.scala
 
b/tests/src/test/scala/whisk/core/loadBalancer/test/ContainerPoolBalancerObjectTests.scala
index 60eda84..fd3252d 100644
--- 
a/tests/src/test/scala/whisk/core/loadBalancer/test/ContainerPoolBalancerObjectTests.scala
+++ 
b/tests/src/test/scala/whisk/core/loadBalancer/test/ContainerPoolBalancerObjectTests.scala
@@ -143,11 +143,14 @@ class ContainerPoolBalancerObjectTests extends FlatSpec 
with Matchers {
     ContainerPoolBalancer.schedule(invs, 16, hash) shouldBe Some(InstanceId(0))
   }
 
-  it should "choose the home invoker if all invokers are overloaded even above 
the muliplied threshold" in {
-    val invs = IndexedSeq((InstanceId(0), Healthy, 51), (InstanceId(1), 
Healthy, 50), (InstanceId(2), Healthy, 49))
-    val hash = 0 // home is 0, stepsize is 1
-
-    ContainerPoolBalancer.schedule(invs, 16, hash) shouldBe Some(InstanceId(0))
+  it should "choose the random invoker if all invokers are overloaded even 
above the muliplied threshold" in {
+    val invs = IndexedSeq((InstanceId(0), Healthy, 33), (InstanceId(1), 
Healthy, 33), (InstanceId(2), Healthy, 33))
+    val invokerBusyThreshold = 11
+    val hash = 0
+    val bruteResult = (0 to 100) map { _ =>
+      ContainerPoolBalancer.schedule(invs, invokerBusyThreshold, 
hash).get.toInt
+    }
+    bruteResult should contain allOf (0, 1, 2)
   }
 
   it should "transparently work with partitioned sets of invokers" in {

-- 
To stop receiving notification emails like this one, please contact
markusthoem...@apache.org.

Reply via email to