cbickel commented on a change in pull request #3240: Add a loadbalancer with 
local state and horizontal invoker sharding.
URL: 
https://github.com/apache/incubator-openwhisk/pull/3240#discussion_r167550757
 
 

 ##########
 File path: 
core/controller/src/main/scala/whisk/core/entitlement/Entitlement.scala
 ##########
 @@ -82,42 +80,63 @@ protected[core] abstract class EntitlementProvider(config: 
WhiskConfig, loadBala
   implicit actorSystem: ActorSystem,
   logging: Logging) {
 
-  private implicit val executionContext = actorSystem.dispatcher
-
-  /**
-   * The number of controllers if HA is enabled, 1 otherwise
-   */
-  private val diviser = if (config.controllerHighAvailability) 
config.controllerInstances.toInt else 1
+  private implicit val executionContext: ExecutionContext = 
actorSystem.dispatcher
 
   /**
    * Allows 20% of additional requests on top of the limit to mitigate 
possible unfair round-robin loadbalancing between
    * controllers
    */
   private val overcommit = if (config.controllerHighAvailability) 1.2 else 1
+  private def dilateLimit(limit: Int): Int = Math.ceil(limit.toDouble * 
overcommit).toInt
 
   /**
-   * Adjust the throttles for a single controller with the diviser and the 
overcommit.
+   * Calculates a possibly dilated limit relative to the current user.
    *
-   * @param originalThrottle The throttle that needs to be adjusted for this 
controller.
+   * @param defaultLimit the default limit across the whole system
+   * @param user the user to apply that limit to
+   * @return a calculated limit
    */
-  private def dilateThrottle(originalThrottle: Int): Int = {
-    Math.ceil((originalThrottle.toDouble / diviser.toDouble) * 
overcommit).toInt
+  private def calculateLimit(defaultLimit: Int, overrideLimit: Identity => 
Option[Int])(user: Identity): Int = {
+    val absoluteLimit = overrideLimit(user).getOrElse(defaultLimit)
+    dilateLimit(absoluteLimit)
+  }
+
+  /**
+   * Calculates a limit which applies only to this instance individually.
+   *
+   * The state needed to correctly check this limit is not shared between all 
instances, which want to check that
+   * limit, so it needs to be divided between the parties who want to perform 
that check.
+   *
+   * @param defaultLimit the default limit across the whole system
+   * @param user the user to apply that limit to
+   * @return a calculated limit
+   */
+  private def calculateIndividualLimit(defaultLimit: Int, overrideLimit: 
Identity => Option[Int])(
+    user: Identity): Int = {
+    val limit = calculateLimit(defaultLimit, overrideLimit)(user)
+    limit / loadBalancer.clusterSize
 
 Review comment:
   If the limit is 1 and we have more than 1 controller, the user won't be able 
to invoke any actions.

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


With regards,
Apache Git Services

Reply via email to