Skip to content

Commit b0baa7b

Browse files
authored
take prewarmed container's memory as used memory (#4911)
* take prewarmed container's memory as used memory * Don't filter prewarmpool for other kinds * Fix test case error
1 parent 2d0c8a7 commit b0baa7b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,12 @@ 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+
128131
val createdContainer =
129132
// Is there enough space on the invoker for this action to be executed.
130-
if (hasPoolSpaceFor(busyPool, r.action.limits.memory.megabytes.MB)) {
133+
if (hasPoolSpaceFor(busyPool ++ prewarmedPool, memory)) {
131134
// Schedule a job to a warm container
132135
ContainerPool
133136
.schedule(r.action, r.msg.user.namespace.name, freePool)
@@ -136,12 +139,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
136139
// There was no warm/warming/warmingCold container. Try to take a prewarm container or a cold container.
137140

138141
// 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)) {
142+
if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPool, memory)) {
140143
takePrewarmContainer(r.action)
141144
.map(container => (container, "prewarmed"))
142145
.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)
146+
val container = Some(createContainer(memory), "cold")
147+
incrementColdStartCount(kind, memory)
145148
container
146149
}
147150
} else None)
@@ -158,8 +161,8 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
158161
takePrewarmContainer(r.action)
159162
.map(container => (container, "recreatedPrewarm"))
160163
.getOrElse {
161-
val container = (createContainer(r.action.limits.memory.megabytes.MB), "recreated")
162-
incrementColdStartCount(r.action.exec.kind, r.action.limits.memory.megabytes.MB)
164+
val container = (createContainer(memory), "recreated")
165+
incrementColdStartCount(kind, memory)
163166
container
164167
}))
165168

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,8 @@ class ContainerPoolTests
329329
val feed = TestProbe()
330330

331331
val pool =
332-
system.actorOf(
333-
ContainerPool
334-
.props(factory, poolConfig(MemoryLimit.STD_MEMORY), feed.ref, List(PrewarmingConfig(1, exec, memoryLimit))))
332+
system.actorOf(ContainerPool
333+
.props(factory, poolConfig(MemoryLimit.STD_MEMORY * 2), feed.ref, List(PrewarmingConfig(1, exec, memoryLimit))))
335334
containers(0).expectMsg(Start(exec, memoryLimit))
336335
containers(0).send(pool, NeedWork(preWarmedData(exec.kind)))
337336
pool ! runMessage
@@ -365,7 +364,7 @@ class ContainerPoolTests
365364
ContainerPool
366365
.props(
367366
factory,
368-
poolConfig(MemoryLimit.STD_MEMORY),
367+
poolConfig(MemoryLimit.STD_MEMORY * 2),
369368
feed.ref,
370369
List(PrewarmingConfig(1, alternativeExec, memoryLimit))))
371370
containers(0).expectMsg(Start(alternativeExec, memoryLimit)) // container0 was prewarmed
@@ -385,7 +384,7 @@ class ContainerPoolTests
385384
ContainerPool
386385
.props(
387386
factory,
388-
poolConfig(MemoryLimit.STD_MEMORY),
387+
poolConfig(MemoryLimit.STD_MEMORY * 2),
389388
feed.ref,
390389
List(PrewarmingConfig(1, exec, alternativeLimit))))
391390
containers(0).expectMsg(Start(exec, alternativeLimit)) // container0 was prewarmed

0 commit comments

Comments
 (0)