Skip to content

Add FPC Load Balancer #5192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 13, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AverageRingBuffer(private val maxSize: Int) {

def nonEmpty: Boolean = elements.nonEmpty

def average: Double = {
def average: Double = {
val size = elements.size
if (size > 2) {
(sum - max - min) / (size - 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ abstract class CommonLoadBalancer(config: WhiskConfig,
protected[loadBalancer] val activationPromises =
TrieMap[ActivationId, Promise[Either[ActivationId, WhiskActivation]]]()
protected val activationsPerNamespace = TrieMap[UUID, LongAdder]()
protected val activationsPerController = TrieMap[ControllerInstanceId, LongAdder]()
protected val activationsPerInvoker = TrieMap[InvokerInstanceId, LongAdder]()
protected val totalActivations = new LongAdder()
protected val totalBlackBoxActivationMemory = new LongAdder()
protected val totalManagedActivationMemory = new LongAdder()
Expand All @@ -83,6 +85,14 @@ abstract class CommonLoadBalancer(config: WhiskConfig,
override def activeActivationsFor(namespace: UUID): Future[Int] =
Future.successful(activationsPerNamespace.get(namespace).map(_.intValue).getOrElse(0))
override def totalActiveActivations: Future[Int] = Future.successful(totalActivations.intValue)
override def activeActivationsByController(controller: String): Future[Int] =
Future.successful(activationsPerController.get(ControllerInstanceId(controller)).map(_.intValue()).getOrElse(0))
override def activeActivationsByController: Future[List[ActivationId]] =
Future.successful(activationSlots.keySet.toList)
override def activeActivationsByInvoker(invoker: String): Future[Int] =
Future.successful(
activationsPerInvoker.get(InvokerInstanceId(invoker.toInt, userMemory = 0.MB)).map(_.intValue()).getOrElse(0))
override def close: Unit = activationFeed ! GracefulShutdown

/**
* Calculate the duration within which a completion ack must be received for an activation.
Expand Down Expand Up @@ -125,6 +135,10 @@ abstract class CommonLoadBalancer(config: WhiskConfig,
totalActivationMemory.add(action.limits.memory.megabytes)

activationsPerNamespace.getOrElseUpdate(msg.user.namespace.uuid, new LongAdder()).increment()
activationsPerController.getOrElseUpdate(controllerInstance, new LongAdder()).increment()
activationsPerInvoker
.getOrElseUpdate(InvokerInstanceId(instance.instance, userMemory = 0.MB), new LongAdder())
.increment()

// Completion Ack must be received within the calculated time.
val completionAckTimeout = calculateCompletionAckTimeout(action.limits.timeout.duration)
Expand Down Expand Up @@ -162,7 +176,8 @@ abstract class CommonLoadBalancer(config: WhiskConfig,
action.fullyQualifiedName(true),
timeoutHandler,
isBlackboxInvocation,
msg.blocking)
msg.blocking,
controllerInstance)
})

resultPromise
Expand Down Expand Up @@ -287,6 +302,10 @@ abstract class CommonLoadBalancer(config: WhiskConfig,
if (entry.isBlackbox) totalBlackBoxActivationMemory else totalManagedActivationMemory
totalActivationMemory.add(entry.memoryLimit.toMB * (-1))
activationsPerNamespace.get(entry.namespaceId).foreach(_.decrement())
activationsPerController.get(entry.controllerId).foreach(_.decrement())
activationsPerInvoker
.get(InvokerInstanceId(entry.invokerName.instance, userMemory = 0.MB))
.foreach(_.decrement())

invoker.foreach(releaseInvoker(_, entry))

Expand Down
Loading