Skip to content

Commit 395149d

Browse files
authored
Reactive prewarm - use proper ttl when replacing a prewarm (#4913)
* use configured ttl when backfilling prewarm
1 parent 8759cad commit 395149d

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
412412
// Create a new prewarm container
413413
// NOTE: prewarming ignores the action code in exec, but this is dangerous as the field is accessible to the
414414
// factory
415-
val ttl = data.expires match {
416-
case Some(value) => Some(value.time)
417-
case None => None
418-
}
415+
416+
//get the appropriate ttl from prewarm configs
417+
val ttl =
418+
prewarmConfig.find(pc => pc.memoryLimit == memory && pc.exec.kind == kind).flatMap(_.reactive.map(_.ttl))
419419
prewarmContainer(action.exec, memory, ttl)
420420
(ref, data)
421421
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,23 @@ class ContainerPoolTests
336336
containers(1).expectMsg(Start(exec, memoryLimit))
337337
}
338338

339+
it should "use a prewarmed container with ttl and create a new one to fill its place" in within(timeout) {
340+
val (containers, factory) = testContainers(2)
341+
val feed = TestProbe()
342+
val ttl = 5.seconds //make sure replaced prewarm has ttl
343+
val pool =
344+
system.actorOf(
345+
ContainerPool
346+
.props(
347+
factory,
348+
poolConfig(MemoryLimit.STD_MEMORY * 2),
349+
feed.ref,
350+
List(PrewarmingConfig(1, exec, memoryLimit, Some(ReactivePrewarmingConfig(1, 1, ttl, 1, 1))))))
351+
containers(0).expectMsg(Start(exec, memoryLimit, Some(ttl)))
352+
containers(0).send(pool, NeedWork(preWarmedData(exec.kind, expires = Some(ttl.fromNow))))
353+
pool ! runMessage
354+
containers(1).expectMsg(Start(exec, memoryLimit, Some(ttl)))
355+
}
339356
it should "not use a prewarmed container if it doesn't fit the kind" in within(timeout) {
340357
val (containers, factory) = testContainers(2)
341358
val feed = TestProbe()

0 commit comments

Comments
 (0)