From 180926afaa41998028839b3d67a1219df6e3a23a Mon Sep 17 00:00:00 2001 From: "ning.yougang" Date: Fri, 22 May 2020 17:02:58 +0800 Subject: [PATCH 1/3] take prewarmed container's memory as used memory --- .../core/containerpool/ContainerPool.scala | 21 +++++++++++++------ .../test/ContainerPoolTests.scala | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala index 4327ad160fb..08c410681eb 100644 --- a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala +++ b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala @@ -125,9 +125,18 @@ 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 prewarmedPoolForOtherKind = prewarmedPool.filter { info => + info match { + case (_, PreWarmedData(_, `kind`, `memory`, _, _)) => false + case _ => true + } + } 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 ++ prewarmedPoolForOtherKind, memory)) { // Schedule a job to a warm container ContainerPool .schedule(r.action, r.msg.user.namespace.name, freePool) @@ -136,12 +145,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 ++ prewarmedPoolForOtherKind, 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) @@ -158,8 +167,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 })) diff --git a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala index 63930fef799..3f3786b8600 100644 --- a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala +++ b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala @@ -365,7 +365,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 @@ -385,7 +385,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 From 2c923a2c123351d1cc7f3d96e147348b24dd09ac Mon Sep 17 00:00:00 2001 From: "ning.yougang" Date: Wed, 9 Sep 2020 09:00:41 +0800 Subject: [PATCH 2/3] Don't filter prewarmpool for other kinds --- .../openwhisk/core/containerpool/ContainerPool.scala | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala index 08c410681eb..92f058bf1fe 100644 --- a/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala +++ b/core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala @@ -128,15 +128,9 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef, val kind = r.action.exec.kind val memory = r.action.limits.memory.megabytes.MB - val prewarmedPoolForOtherKind = prewarmedPool.filter { info => - info match { - case (_, PreWarmedData(_, `kind`, `memory`, _, _)) => false - case _ => true - } - } val createdContainer = // Is there enough space on the invoker for this action to be executed. - if (hasPoolSpaceFor(busyPool ++ prewarmedPoolForOtherKind, memory)) { + if (hasPoolSpaceFor(busyPool ++ prewarmedPool, memory)) { // Schedule a job to a warm container ContainerPool .schedule(r.action, r.msg.user.namespace.name, freePool) @@ -145,7 +139,7 @@ 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 ++ prewarmedPoolForOtherKind, memory)) { + if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPool, memory)) { takePrewarmContainer(r.action) .map(container => (container, "prewarmed")) .orElse { From 22db3cbcfb4122effbc396353ba00f960a71ffa1 Mon Sep 17 00:00:00 2001 From: "ning.yougang" Date: Fri, 20 Nov 2020 15:13:53 +0800 Subject: [PATCH 3/3] Fix test case error --- .../core/containerpool/test/ContainerPoolTests.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala index 3f3786b8600..3fd04143c06 100644 --- a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala +++ b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/test/ContainerPoolTests.scala @@ -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