Skip to content

Commit 6b30317

Browse files
committed
take prewarmed container's memory as used memory
1 parent 74c5418 commit 6b30317

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,18 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
134134
//remove from resent tracking - it may get resent again, or get processed
135135
resent = None
136136
}
137+
val kind = r.action.exec.kind
138+
val memory = r.action.limits.memory.megabytes.MB
139+
140+
val prewarmedPoolForOtherKind = prewarmedPool.filter { info =>
141+
info match {
142+
case (_, PreWarmedData(_, `kind`, `memory`, _, _)) => false
143+
case _ => true
144+
}
145+
}
137146
val createdContainer =
138147
// Is there enough space on the invoker for this action to be executed.
139-
if (hasPoolSpaceFor(busyPool, r.action.limits.memory.megabytes.MB)) {
148+
if (hasPoolSpaceFor(busyPool ++ prewarmedPoolForOtherKind, memory)) {
140149
// Schedule a job to a warm container
141150
ContainerPool
142151
.schedule(r.action, r.msg.user.namespace.name, freePool)
@@ -145,12 +154,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
145154
// There was no warm/warming/warmingCold container. Try to take a prewarm container or a cold container.
146155

147156
// Is there enough space to create a new container or do other containers have to be removed?
148-
if (hasPoolSpaceFor(busyPool ++ freePool, r.action.limits.memory.megabytes.MB)) {
157+
if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPoolForOtherKind, memory)) {
149158
takePrewarmContainer(r.action)
150159
.map(container => (container, "prewarmed"))
151160
.orElse {
152-
val container = Some(createContainer(r.action.limits.memory.megabytes.MB), "cold")
153-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
161+
val container = Some(createContainer(memory), "cold")
162+
incrementColdStartCount(kind, memory)
154163
container
155164
}
156165
} else None)
@@ -167,8 +176,8 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
167176
takePrewarmContainer(r.action)
168177
.map(container => (container, "recreatedPrewarm"))
169178
.getOrElse {
170-
val container = (createContainer(r.action.limits.memory.megabytes.MB), "recreated")
171-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
179+
val container = (createContainer(memory), "recreated")
180+
incrementColdStartCount(kind, memory)
172181
container
173182
}))
174183

tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class ContainerPoolTests
364364
ContainerPool
365365
.props(
366366
factory,
367-
poolConfig(MemoryLimit.STD_MEMORY),
367+
poolConfig(MemoryLimit.STD_MEMORY * 2),
368368
feed.ref,
369369
List(PrewarmingConfig(1, alternativeExec, memoryLimit))))
370370
containers(0).expectMsg(Start(alternativeExec, memoryLimit)) // container0 was prewarmed
@@ -384,7 +384,7 @@ class ContainerPoolTests
384384
ContainerPool
385385
.props(
386386
factory,
387-
poolConfig(MemoryLimit.STD_MEMORY),
387+
poolConfig(MemoryLimit.STD_MEMORY * 2),
388388
feed.ref,
389389
List(PrewarmingConfig(1, exec, alternativeLimit))))
390390
containers(0).expectMsg(Start(exec, alternativeLimit)) // container0 was prewarmed

0 commit comments

Comments
 (0)