bdoyle0182 commented on PR #5344:
URL: https://github.com/apache/openwhisk/pull/5344#issuecomment-1292752659

   I think an additional optimization would be to do the stale calculation and 
normal available message case in the same decision such that we take this code:
   
   ```
             case (Running, Some(duration)) if staleActivationNum > 0 =>
               // we can safely get the value as we already checked the 
existence
               val containerThroughput = staleThreshold / duration
               val num = ceiling(staleActivationNum.toDouble / 
containerThroughput)
               // if it tries to create more containers than existing messages, 
we just create shortage
               val actualNum = (if (num > staleActivationNum) 
staleActivationNum else num) - inProgress
               addServersIfPossible(
                 existing,
                 inProgress,
                 containerThroughput,
                 availableMsg,
                 capacity,
                 actualNum,
                 staleActivationNum,
                 duration,
                 Running)
   
             // need more containers and a message is already processed
             case (Running, Some(duration)) =>
               // we can safely get the value as we already checked the 
existence
               val containerThroughput = staleThreshold / duration
               val expectedTps = containerThroughput * (existing + inProgress)
   
               if (availableMsg >= expectedTps && existing + inProgress < 
availableMsg) {
                 val num = ceiling((availableMsg / containerThroughput) - 
existing - inProgress)
                 // if it tries to create more containers than existing 
messages, we just create shortage
                 val actualNum = if (num + totalContainers > availableMsg) 
availableMsg - totalContainers else num
                 addServersIfPossible(
                   existing,
                   inProgress,
                   containerThroughput,
                   availableMsg,
                   capacity,
                   actualNum,
                   staleActivationNum,
                   duration,
                   Running)
               } else {
                 Future.successful(DecisionResults(Skip, 0))
               }
               ```
     and consolidate it to this:
     
     ```
               // need more containers and a message is already processed
             case (Running, Some(duration)) =>
               // we can safely get the value as we already checked the 
existence
               val containerThroughput = staleThreshold / duration
               val expectedTps = containerThroughput * (existing + inProgress)
               val availableNonStaleActivations = availableMsg - 
staleActivationNum
               
               var staleContainerProvision = 0
               if (staleActivationNum > 0) {
                 val num = ceiling(staleActivationNum.toDouble / 
containerThroughput)
                 // if it tries to create more containers than existing 
messages, we just create shortage
                 staleContainerProvision = (if (num > staleActivationNum) 
staleActivationNum else num) - inProgress
               }
               
               if (availableNonStaleActivations >= expectedTps && existing + 
inProgress < availableMsg) {
                 val num = ceiling((availableNonStaleActivations / 
containerThroughput) - existing - inProgress)
                 // if it tries to create more containers than existing 
messages, we just create shortage
                 val actualNum = if (num + totalContainers > 
availableNonStaleActivations) availableNonStaleActivations - totalContainers 
else num
                 addServersIfPossible(
                   existing,
                   inProgress,
                   containerThroughput,
                   availableMsg,
                   capacity,
                   actualNum + staleContainerProvision,
                   staleActivationNum,
                   duration,
                   Running)
               } else if (staleContainerProvision > 0) {
                 addServersIfPossible(
                   existing,
                   inProgress,
                   containerThroughput,
                   availableMsg,
                   capacity,
                   staleContainerProvision,
                   staleActivationNum,
                   duration,
                   Running)
               } else {
                 Future.successful(DecisionResults(Skip, 0))
               }
   ```
   
   such that if you do need more containers for available msg, you don't need 
to wait an additional scheduling interval to create them. So take the same 
example from the description and say that there are 6 existing containers. The 
second code block will create 1 container for the stale activations and 5 
containers for the 100 available messages that are not stale bringing us to the 
correct 11 capacity in one scheduling interval. If there were already 10 
containers available like in the original example and we just need 1 additional 
container for the stale activations it would enter the `else if` case and just 
add the 1 container to account for the stale activations to bring it to 11.
               


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to