Skip to content

Commit 370ddef

Browse files
committed
take prewarmed container's memory as used memory
1 parent 1274fdf commit 370ddef

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
@@ -131,9 +131,18 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
131131
//remove from resent tracking - it may get resent again, or get processed
132132
resent = None
133133
}
134+
val kind = r.action.exec.kind
135+
val memory = r.action.limits.memory.megabytes.MB
136+
137+
val prewarmedPoolForOtherKind = prewarmedPool.filter { info =>
138+
info match {
139+
case (_, PreWarmedData(_, `kind`, `memory`, _, _)) => false
140+
case _ => true
141+
}
142+
}
134143
val createdContainer =
135144
// Is there enough space on the invoker for this action to be executed.
136-
if (hasPoolSpaceFor(busyPool, r.action.limits.memory.megabytes.MB)) {
145+
if (hasPoolSpaceFor(busyPool ++ prewarmedPoolForOtherKind, memory)) {
137146
// Schedule a job to a warm container
138147
ContainerPool
139148
.schedule(r.action, r.msg.user.namespace.name, freePool)
@@ -142,12 +151,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
142151
// There was no warm/warming/warmingCold container. Try to take a prewarm container or a cold container.
143152

144153
// Is there enough space to create a new container or do other containers have to be removed?
145-
if (hasPoolSpaceFor(busyPool ++ freePool, r.action.limits.memory.megabytes.MB)) {
154+
if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPoolForOtherKind, memory)) {
146155
takePrewarmContainer(r.action)
147156
.map(container => (container, "prewarmed"))
148157
.orElse {
149-
val container = Some(createContainer(r.action.limits.memory.megabytes.MB), "cold")
150-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
158+
val container = Some(createContainer(memory), "cold")
159+
incrementColdStartCount(kind, memory)
151160
container
152161
}
153162
} else None)
@@ -164,8 +173,8 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
164173
takePrewarmContainer(r.action)
165174
.map(container => (container, "recreatedPrewarm"))
166175
.getOrElse {
167-
val container = (createContainer(r.action.limits.memory.megabytes.MB), "recreated")
168-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
176+
val container = (createContainer(memory), "recreated")
177+
incrementColdStartCount(kind, memory)
169178
container
170179
}))
171180

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
@@ -346,7 +346,7 @@ class ContainerPoolTests
346346
ContainerPool
347347
.props(
348348
factory,
349-
poolConfig(MemoryLimit.STD_MEMORY),
349+
poolConfig(MemoryLimit.STD_MEMORY * 2),
350350
feed.ref,
351351
List(PrewarmingConfig(1, alternativeExec, memoryLimit))))
352352
containers(0).expectMsg(Start(alternativeExec, memoryLimit)) // container0 was prewarmed
@@ -366,7 +366,7 @@ class ContainerPoolTests
366366
ContainerPool
367367
.props(
368368
factory,
369-
poolConfig(MemoryLimit.STD_MEMORY),
369+
poolConfig(MemoryLimit.STD_MEMORY * 2),
370370
feed.ref,
371371
List(PrewarmingConfig(1, exec, alternativeLimit))))
372372
containers(0).expectMsg(Start(exec, alternativeLimit)) // container0 was prewarmed

0 commit comments

Comments
 (0)