You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/10/24 06:06:15 UTC

[GitHub] ningyougang closed pull request #4077: Fix bug of cal manged and blackboxes number

ningyougang closed pull request #4077: Fix bug of cal manged and blackboxes number
URL: https://github.com/apache/incubator-openwhisk/pull/4077
 
 
   

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/core/controller/src/main/scala/whisk/core/loadBalancer/ShardingContainerPoolBalancer.scala b/core/controller/src/main/scala/whisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
index 66f66a2fe1..254488d0c0 100644
--- a/core/controller/src/main/scala/whisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
+++ b/core/controller/src/main/scala/whisk/core/loadBalancer/ShardingContainerPoolBalancer.scala
@@ -571,8 +571,8 @@ case class ShardingContainerPoolBalancerState(
 
     // for small N, allow the managed invokers to overlap with blackbox invokers, and
     // further assume that blackbox invokers << managed invokers
-    val managed = Math.max(1, Math.ceil(newSize.toDouble * (1 - blackboxFraction)).toInt)
-    val blackboxes = Math.max(1, Math.floor(newSize.toDouble * blackboxFraction).toInt)
+    val blackboxes = Math.max(1, Math.round(newSize.toDouble * blackboxFraction).toInt)
+    val managed = Math.max(1, newSize - blackboxes)
 
     _invokers = newInvokers
     _managedInvokers = _invokers.take(managed)
diff --git a/tests/src/test/scala/whisk/core/loadBalancer/test/ShardingContainerPoolBalancerTests.scala b/tests/src/test/scala/whisk/core/loadBalancer/test/ShardingContainerPoolBalancerTests.scala
index be0dc007fb..87079312e0 100644
--- a/tests/src/test/scala/whisk/core/loadBalancer/test/ShardingContainerPoolBalancerTests.scala
+++ b/tests/src/test/scala/whisk/core/loadBalancer/test/ShardingContainerPoolBalancerTests.scala
@@ -96,26 +96,23 @@ class ShardingContainerPoolBalancerTests extends FlatSpec with Matchers with Str
   }
 
   it should "allow managed partition to overlap with blackbox for small N" in {
-    Seq(0.1, 0.2, 0.3, 0.4, 0.5).foreach { bf =>
+    Seq(0.1, 0.2, 0.3, 0.4, 0.5, 0.9, 0.99).foreach { bf =>
       val state = ShardingContainerPoolBalancerState()(lbConfig(bf))
 
       (1 to 100).toSeq.foreach { i =>
-        state.updateInvokers((1 to i).map(_ => healthy(1, MemoryLimit.stdMemory)))
+        state.updateInvokers((1 to i).map(i => healthy(i, MemoryLimit.stdMemory)))
 
         withClue(s"invoker count $bf $i:") {
-          state.managedInvokers.length should be <= i
-          state.blackboxInvokers should have size Math.max(1, (bf * i).toInt)
+          state.blackboxInvokers should have size Math.max(1, Math.round(bf * i).toInt)
+          state.managedInvokers should have size Math.max(1, i - state.blackboxInvokers.length)
 
           val m = state.managedInvokers.length
           val b = state.blackboxInvokers.length
-          bf match {
-            // written out explicitly for clarity
-            case 0.1 if i < 10 => m + b shouldBe i + 1
-            case 0.2 if i < 5  => m + b shouldBe i + 1
-            case 0.3 if i < 4  => m + b shouldBe i + 1
-            case 0.4 if i < 3  => m + b shouldBe i + 1
-            case 0.5 if i < 2  => m + b shouldBe i + 1
-            case _             => m + b shouldBe i
+
+          if (i == 1 || Math.round(bf * i).toInt == i) {
+            m + b shouldBe i + 1
+          } else {
+            m + b shouldBe i
           }
         }
       }


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services