Skip to content

Commit 180926a

Browse files
committed
take prewarmed container's memory as used memory
1 parent 2d0c8a7 commit 180926a

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
@@ -125,9 +125,18 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
125125
//remove from resent tracking - it may get resent again, or get processed
126126
resent = None
127127
}
128+
val kind = r.action.exec.kind
129+
val memory = r.action.limits.memory.megabytes.MB
130+
131+
val prewarmedPoolForOtherKind = prewarmedPool.filter { info =>
132+
info match {
133+
case (_, PreWarmedData(_, `kind`, `memory`, _, _)) => false
134+
case _ => true
135+
}
136+
}
128137
val createdContainer =
129138
// Is there enough space on the invoker for this action to be executed.
130-
if (hasPoolSpaceFor(busyPool, r.action.limits.memory.megabytes.MB)) {
139+
if (hasPoolSpaceFor(busyPool ++ prewarmedPoolForOtherKind, memory)) {
131140
// Schedule a job to a warm container
132141
ContainerPool
133142
.schedule(r.action, r.msg.user.namespace.name, freePool)
@@ -136,12 +145,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
136145
// There was no warm/warming/warmingCold container. Try to take a prewarm container or a cold container.
137146

138147
// Is there enough space to create a new container or do other containers have to be removed?
139-
if (hasPoolSpaceFor(busyPool ++ freePool, r.action.limits.memory.megabytes.MB)) {
148+
if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPoolForOtherKind, memory)) {
140149
takePrewarmContainer(r.action)
141150
.map(container => (container, "prewarmed"))
142151
.orElse {
143-
val container = Some(createContainer(r.action.limits.memory.megabytes.MB), "cold")
144-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
152+
val container = Some(createContainer(memory), "cold")
153+
incrementColdStartCount(kind, memory)
145154
container
146155
}
147156
} else None)
@@ -158,8 +167,8 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
158167
takePrewarmContainer(r.action)
159168
.map(container => (container, "recreatedPrewarm"))
160169
.getOrElse {
161-
val container = (createContainer(r.action.limits.memory.megabytes.MB), "recreated")
162-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
170+
val container = (createContainer(memory), "recreated")
171+
incrementColdStartCount(kind, memory)
163172
container
164173
}))
165174

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
@@ -365,7 +365,7 @@ class ContainerPoolTests
365365
ContainerPool
366366
.props(
367367
factory,
368-
poolConfig(MemoryLimit.STD_MEMORY),
368+
poolConfig(MemoryLimit.STD_MEMORY * 2),
369369
feed.ref,
370370
List(PrewarmingConfig(1, alternativeExec, memoryLimit))))
371371
containers(0).expectMsg(Start(alternativeExec, memoryLimit)) // container0 was prewarmed
@@ -385,7 +385,7 @@ class ContainerPoolTests
385385
ContainerPool
386386
.props(
387387
factory,
388-
poolConfig(MemoryLimit.STD_MEMORY),
388+
poolConfig(MemoryLimit.STD_MEMORY * 2),
389389
feed.ref,
390390
List(PrewarmingConfig(1, exec, alternativeLimit))))
391391
containers(0).expectMsg(Start(exec, alternativeLimit)) // container0 was prewarmed

0 commit comments

Comments
 (0)