rabbah commented on a change in pull request #2587: Make LoadbalancerData 
leaner.
URL: 
https://github.com/apache/incubator-openwhisk/pull/2587#discussion_r132830503
 
 

 ##########
 File path: 
core/controller/src/main/scala/whisk/core/loadBalancer/LoadBalancerData.scala
 ##########
 @@ -33,28 +36,32 @@ case class ActivationEntry(id: ActivationId, namespaceId: 
UUID, invokerName: Ins
  */
 class LoadBalancerData() {
 
-    type TrieSet[T] = TrieMap[T, Unit]
+    private val activationByInvoker = TrieMap[InstanceId, AtomicInteger]()
+    private val activationByNamespaceId = TrieMap[UUID, AtomicInteger]()
+    private val activationsById = TrieMap[ActivationId, ActivationEntry]()
+    private val totalActivations = new AtomicInteger(0)
 
-    private val activationByInvoker = new TrieMap[InstanceId, 
TrieSet[ActivationEntry]]
-    private val activationByNamespaceId = new TrieMap[UUID, 
TrieSet[ActivationEntry]]
-    private val activationsById = new TrieMap[ActivationId, ActivationEntry]
+    /** Get the number of activations across all namespaces. */
+    def totalActivationCount = totalActivations.get
 
     /**
-     * Get the number of activations for each namespace.
+     * Get the number of activations for a specific namespace.
      *
+     * @param namespace The namespace to get the activation count for
      * @return a map (namespace -> number of activations in the system)
      */
-    def activationCountByNamespace: Map[UUID, Int] = {
-        activationByNamespaceId.toMap.mapValues(_.size)
+    def activationCountOn(namespace: UUID) = {
+        activationByNamespaceId.get(namespace).map(_.get).getOrElse(0)
     }
 
     /**
-     * Get the number of activations for each invoker.
+     * Get the number of activations for a specific invoker.
      *
+     * @param invoker The invoker to get the activation count for
      * @return a map (invoker -> number of activations queued for the invoker)
      */
-    def activationCountByInvoker: Map[InstanceId, Int] = {
-        activationByInvoker.toMap.mapValues(_.size)
+    def activationCountOn(invoker: InstanceId): Int = {
+        activationByInvoker.get(invoker).map(_.get).getOrElse(0)
 
 Review comment:
   seeing usage below - i suppose 0 is fine.
 
----------------------------------------------------------------
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