Skip to content

Add Function Cache Refresh If Invoker Is Running Container For Function #5327

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 4 commits into from
Sep 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ package org.apache.openwhisk.core.containerpool.v2

import java.net.InetSocketAddress
import java.time.Instant

import akka.actor.Status.{Failure => FailureMessage}
import akka.actor.{ActorRef, ActorRefFactory, ActorSystem, FSM, Props, Stash}
import akka.actor.{actorRef2Scala, ActorRef, ActorRefFactory, ActorSystem, FSM, Props, Stash}
import akka.event.Logging.InfoLevel
import akka.io.{IO, Tcp}
import akka.pattern.pipe
Expand Down Expand Up @@ -87,6 +86,7 @@ case class Initialized(data: InitializedData)
case class Resumed(data: WarmData)
case class ResumeFailed(data: WarmData)
case class RecreateClient(action: ExecutableWhiskAction)
case object PingCache
case class DetermineKeepContainer(attempt: Int)

// States
Expand Down Expand Up @@ -209,7 +209,8 @@ class FunctionPullingContainerProxy(
private val KeepingTimeoutName = "KeepingTimeout"
private val RunningActivationTimeoutName = "RunningActivationTimeout"
private val runningActivationTimeout = 10.seconds

private val PingCacheName = "PingCache"
private val pingCacheInterval = 1.minute
private var timedOut = false

var healthPingActor: Option[ActorRef] = None //setup after prewarm starts
Expand Down Expand Up @@ -374,6 +375,7 @@ class FunctionPullingContainerProxy(
case Event(initializedData: InitializedData, _) =>
context.parent ! Initialized(initializedData)
initializedData.clientProxy ! RequestActivation()
startTimerWithFixedDelay(PingCacheName, PingCache, pingCacheInterval)
startSingleTimer(UnusedTimeoutName, StateTimeout, unusedTimeout)
stay() using initializedData

Expand Down Expand Up @@ -469,7 +471,7 @@ class FunctionPullingContainerProxy(
data.action.rev,
None)

case _ => delay
case x: Event if x.event != PingCache => delay
}

when(Rescheduling, stateTimeout = 10.seconds) {
Expand Down Expand Up @@ -626,7 +628,7 @@ class FunctionPullingContainerProxy(
data.clientProxy ! CloseClientProxy
stay

case _ => delay
case x: Event if x.event != PingCache => delay
}

when(Pausing) {
Expand All @@ -653,7 +655,7 @@ class FunctionPullingContainerProxy(
data.action.rev,
Some(data.clientProxy))

case _ => delay
case x: Event if x.event != PingCache => delay
}

when(Paused) {
Expand Down Expand Up @@ -745,7 +747,8 @@ class FunctionPullingContainerProxy(
data.action.fullyQualifiedName(false),
data.action.rev,
Some(data.clientProxy))
case _ => delay

case x: Event if x.event != PingCache => delay
}

when(Removing, unusedTimeout) {
Expand All @@ -768,6 +771,20 @@ class FunctionPullingContainerProxy(
stay()
}

whenUnhandled {
case Event(PingCache, data: WarmData) =>
val actionId = data.action.fullyQualifiedName(false).toDocId.asDocInfo(data.revision)
get(entityStore, actionId.id, actionId.rev, true).map(_ => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve the performance? to sync the action data from Couchdb with interval time.

logging.debug(
this,
s"Refreshed function cache for action ${data.action} from container ${data.container.containerId}.")
})
stay
case Event(PingCache, _) =>
logging.debug(this, "Container is not warm, ignore function cache ping.")
stay
}

onTransition {
case _ -> Uninitialized => unstashAll()
case _ -> CreatingContainer => unstashAll()
Expand Down Expand Up @@ -823,15 +840,14 @@ class FunctionPullingContainerProxy(
fqn: FullyQualifiedEntityName,
revision: DocRevision,
clientProxy: Option[ActorRef]): State = {

cancelTimer(PingCacheName)
dataManagementService ! UnregisterData(
s"${ContainerKeys.existingContainers(invocationNamespace, fqn, revision, Some(instance), Some(container.containerId))}")

cleanUp(container, clientProxy)
}

private def cleanUp(container: Container, clientProxy: Option[ActorRef], replacePrewarm: Boolean = true): State = {

context.parent ! ContainerRemoved(replacePrewarm)
val unpause = stateName match {
case Paused => container.resume()(TransactionId.invokerNanny)
Expand Down