This is an automated email from the ASF dual-hosted git repository.

tysonnorris pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 395149d  Reactive prewarm - use proper ttl when replacing a prewarm 
(#4913)
395149d is described below

commit 395149d7e3d07e379e053c778ae6ed6f32eef33e
Author: tysonnorris <[email protected]>
AuthorDate: Thu Jun 4 14:55:02 2020 -0700

    Reactive prewarm - use proper ttl when replacing a prewarm (#4913)
    
    * use configured ttl when backfilling prewarm
---
 .../openwhisk/core/containerpool/ContainerPool.scala    |  8 ++++----
 .../core/containerpool/test/ContainerPoolTests.scala    | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 4 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 8c3dcb1..58cad8c 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
@@ -412,10 +412,10 @@ class ContainerPool(childFactory: ActorRefFactory => 
ActorRef,
           // Create a new prewarm container
           // NOTE: prewarming ignores the action code in exec, but this is 
dangerous as the field is accessible to the
           // factory
-          val ttl = data.expires match {
-            case Some(value) => Some(value.time)
-            case None        => None
-          }
+
+          //get the appropriate ttl from prewarm configs
+          val ttl =
+            prewarmConfig.find(pc => pc.memoryLimit == memory && pc.exec.kind 
== kind).flatMap(_.reactive.map(_.ttl))
           prewarmContainer(action.exec, memory, ttl)
           (ref, data)
       }
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 399bf88..d684342 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
@@ -336,6 +336,23 @@ class ContainerPoolTests
     containers(1).expectMsg(Start(exec, memoryLimit))
   }
 
+  it should "use a prewarmed container with ttl and create a new one to fill 
its place" in within(timeout) {
+    val (containers, factory) = testContainers(2)
+    val feed = TestProbe()
+    val ttl = 5.seconds //make sure replaced prewarm has ttl
+    val pool =
+      system.actorOf(
+        ContainerPool
+          .props(
+            factory,
+            poolConfig(MemoryLimit.STD_MEMORY * 2),
+            feed.ref,
+            List(PrewarmingConfig(1, exec, memoryLimit, 
Some(ReactivePrewarmingConfig(1, 1, ttl, 1, 1))))))
+    containers(0).expectMsg(Start(exec, memoryLimit, Some(ttl)))
+    containers(0).send(pool, NeedWork(preWarmedData(exec.kind, expires = 
Some(ttl.fromNow))))
+    pool ! runMessage
+    containers(1).expectMsg(Start(exec, memoryLimit, Some(ttl)))
+  }
   it should "not use a prewarmed container if it doesn't fit the kind" in 
within(timeout) {
     val (containers, factory) = testContainers(2)
     val feed = TestProbe()

Reply via email to