rabbah commented on a change in pull request #2360: Choose target invoker based 
on specific invoker load.
URL: 
https://github.com/apache/incubator-openwhisk/pull/2360#discussion_r122568453
 
 

 ##########
 File path: 
core/controller/src/main/scala/whisk/core/loadBalancer/LoadBalancerService.scala
 ##########
 @@ -277,14 +277,44 @@ class LoadBalancerService(config: WhiskConfig, 
entityStore: EntityStore)(implici
             case _              => false
         }
         val invokers = if (isBlackbox) blackboxInvokers else managedInvokers
-        val (hash, count) = hashAndCountSubjectAction(msg)
+        val hash = hashSubjectAction(msg).abs
 
         invokers.flatMap { invokers =>
             val numInvokers = invokers.length
             if (numInvokers > 0) {
-                val hashCount = math.abs(hash + count / 
activationCountBeforeNextInvoker)
-                val invokerIndex = hashCount % numInvokers
-                Future.successful(invokers(invokerIndex))
+                val nextInvokerThreshold = 
config.loadbalancerInvokerBusyThreshold
+                val homeInvoker = hash % numInvokers
+
+                val stepSizes = coprimePrimeNumbersUntil(numInvokers)
+                val step = stepSizes(hash % stepSizes.size)
+
+                /*
+                 * Scans through all invokers and searches for an invoker, 
which's queue is below
+                 * the defined threshold. Iff no "underloaded" container was 
found it will default
+                 * to the least loaded invoker in the list.
+                 *
+                 * @param targetInvoker index of the invoker-candidate.
+                 * @return name of the target invoker
+                 */
+                @tailrec
+                def search(targetInvoker: Int): String = {
+                    val invokerName = invokers(targetInvoker)
+
+                    if 
(activationByInvoker.get(invokerName).map(_.size).getOrElse(0) < 
nextInvokerThreshold) {
 
 Review comment:
   how about some comments
   
   ```
   +                    // send the request to the target invoker if it has 
capacity...
                        if 
(activationByInvoker.get(invokerName).map(_.size).getOrElse(0) < 
nextInvokerThreshold) {
                            invokerName
                        } else {
   +                        // ... otherwise look for a less loaded invoker by 
stepping through a pre computed
   +                        // list of invokers; there are two possible 
outcomes:
   +                        // 1. the search lands on a new invoker that has 
capacity, choose it
   +                        // 2. walked through the entire list and found no 
better invoker than the "home invoker", choose the least loaded invoker
   ```
 
----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to