Skip to content

Commit

Permalink
Allow invoker pools to overlap for small N. (#3751)
Browse files Browse the repository at this point in the history
For small N, allow the managed invokers to overlap with blackbox invokers.
As an example, for a blackbox fraction of 10%, and two invokers, the blackbox
pool will have size 1, but the managed pool will utilize both invokers.
  • Loading branch information
rabbah authored and markusthoemmes committed Jun 18, 2018
1 parent 9e5cec1 commit 4181f7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,14 @@ case class ShardingContainerPoolBalancerState(
val oldSize = _invokers.size
val newSize = newInvokers.size

val blackboxes = Math.max(1, (newSize.toDouble * blackboxFraction).toInt)
val managed = Math.max(1, newSize - blackboxes)
// 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)

_invokers = newInvokers
_blackboxInvokers = _invokers.takeRight(blackboxes)
_managedInvokers = _invokers.take(managed)
_blackboxInvokers = _invokers.takeRight(blackboxes)

if (oldSize != newSize) {
_managedStepSizes = ShardingContainerPoolBalancer.pairwiseCoprimeNumbersUntil(managed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@ class ShardingContainerPoolBalancerTests extends FlatSpec with Matchers with Str
state.blackboxStepSizes shouldBe Seq(1)
}

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 =>
val state = ShardingContainerPoolBalancerState()(ShardingContainerPoolBalancerConfig(bf, 1))

(1 to 100).toSeq.foreach { i =>
state.updateInvokers((1 to i).map(_ => healthy(1)))

withClue(s"invoker count $bf $i:") {
state.managedInvokers.length should be <= i
state.blackboxInvokers should have size Math.max(1, (bf * i).toInt)

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
}
}
}
}
}

it should "update the cluster size, adjusting the invoker slots accordingly" in {
val slots = 10
val state = ShardingContainerPoolBalancerState()(ShardingContainerPoolBalancerConfig(0.5, slots))
Expand Down

0 comments on commit 4181f7c

Please sign in to comment.