markusthoemmes 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_r122960076
##########
File path:
core/controller/src/main/scala/whisk/core/loadBalancer/LoadBalancerService.scala
##########
@@ -312,14 +312,13 @@ object LoadBalancerService {
override def apply(key: I) = getOrElseUpdate(key, f(key))
}
- /** All prime coprime numbers until x including 1. Result is memoized. */
- val coprimePrimeNumbersUntil: Int => IndexedSeq[Int] =
LoadBalancerService.memoize {
- case x =>
- 1 +: (1 to x).foldLeft(IndexedSeq.empty[Int])((primes, cur) => {
- if (x % cur != 0 && !primes.exists(cur % _ == 0)) {
- primes :+ cur
- } else primes
- })
+ /** Eclidean algorithm to determine the greatest-common-divisor */
+ @tailrec
+ def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
+
+ /** All coprime numbers until x including 1. Result is memoized. */
+ val coprimeNumbersUntil: Int => IndexedSeq[Int] =
LoadBalancerService.memoize {
+ case x => (1 to x).filter(i => gcd(i, x) == 1)
Review comment:
It didn't actually compute coprime numbers but numbers that don't divide the
upperbound, which is wrong for this scenario.
----------------------------------------------------------------
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