Skip to content
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

take prewarmed container's memory as used memory #4911

Merged
Merged
Show file tree
Hide file tree
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 @@ -125,9 +125,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
//remove from resent tracking - it may get resent again, or get processed
resent = None
}
val kind = r.action.exec.kind
val memory = r.action.limits.memory.megabytes.MB

val createdContainer =
// Is there enough space on the invoker for this action to be executed.
if (hasPoolSpaceFor(busyPool, r.action.limits.memory.megabytes.MB)) {
if (hasPoolSpaceFor(busyPool ++ prewarmedPool, memory)) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel this needs proper documentation.

// Schedule a job to a warm container
ContainerPool
.schedule(r.action, r.msg.user.namespace.name, freePool)
Expand All @@ -136,12 +139,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
// There was no warm/warming/warmingCold container. Try to take a prewarm container or a cold container.

// Is there enough space to create a new container or do other containers have to be removed?
if (hasPoolSpaceFor(busyPool ++ freePool, r.action.limits.memory.megabytes.MB)) {
if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPool, memory)) {
takePrewarmContainer(r.action)
.map(container => (container, "prewarmed"))
.orElse {
val container = Some(createContainer(r.action.limits.memory.megabytes.MB), "cold")
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
val container = Some(createContainer(memory), "cold")
incrementColdStartCount(kind, memory)
container
}
} else None)
Expand All @@ -158,8 +161,8 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
takePrewarmContainer(r.action)
.map(container => (container, "recreatedPrewarm"))
.getOrElse {
val container = (createContainer(r.action.limits.memory.megabytes.MB), "recreated")
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
val container = (createContainer(memory), "recreated")
incrementColdStartCount(kind, memory)
container
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,8 @@ class ContainerPoolTests
val feed = TestProbe()

val pool =
system.actorOf(
ContainerPool
.props(factory, poolConfig(MemoryLimit.STD_MEMORY), feed.ref, List(PrewarmingConfig(1, exec, memoryLimit))))
system.actorOf(ContainerPool
.props(factory, poolConfig(MemoryLimit.STD_MEMORY * 2), feed.ref, List(PrewarmingConfig(1, exec, memoryLimit))))
containers(0).expectMsg(Start(exec, memoryLimit))
containers(0).send(pool, NeedWork(preWarmedData(exec.kind)))
pool ! runMessage
Expand Down Expand Up @@ -365,7 +364,7 @@ class ContainerPoolTests
ContainerPool
.props(
factory,
poolConfig(MemoryLimit.STD_MEMORY),
poolConfig(MemoryLimit.STD_MEMORY * 2),
feed.ref,
List(PrewarmingConfig(1, alternativeExec, memoryLimit))))
containers(0).expectMsg(Start(alternativeExec, memoryLimit)) // container0 was prewarmed
Expand All @@ -385,7 +384,7 @@ class ContainerPoolTests
ContainerPool
.props(
factory,
poolConfig(MemoryLimit.STD_MEMORY),
poolConfig(MemoryLimit.STD_MEMORY * 2),
feed.ref,
List(PrewarmingConfig(1, exec, alternativeLimit))))
containers(0).expectMsg(Start(exec, alternativeLimit)) // container0 was prewarmed
Expand Down