You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/04/08 22:14:58 UTC

[GitHub] [openwhisk] tysonnorris commented on a change in pull request #4871: Adjust prewarm container dynamically

tysonnorris commented on a change in pull request #4871: Adjust prewarm container dynamically
URL: https://github.com/apache/openwhisk/pull/4871#discussion_r405846072
 
 

 ##########
 File path: core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala
 ##########
 @@ -340,6 +401,41 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
     newContainer ! Start(exec, memoryLimit)
   }
 
+  /** Create a new prewarm container if currentCount doesn't reach maximum */
+  def prewarmContainerIfpossible(kind: String, memoryLimit: ByteSize, count: Int): Unit = {
+    prewarmConfig
+      .filter { config =>
+        kind == config.exec.kind && memoryLimit == config.memoryLimit
+      }
+      .foreach { config =>
+        val currentCount = prewarmedPool.count {
+          case (_, PreWarmedData(_, `kind`, `memoryLimit`, _)) => true //done starting
+          case _                                               => false //started but not finished starting
+        }
+        val startingCount = prewarmStartingPool.count(p => p._2._1 == kind && p._2._2 == memoryLimit)
+        val containerCount = currentCount + startingCount
+        if (containerCount < config.count) {
+          val createNumber = if (config.count - containerCount > count) count else config.count - containerCount
+          1 to createNumber foreach { _ =>
+            prewarmContainer(config.exec, config.memoryLimit)
+          }
+        }
+      }
+  }
+
+  /** statistics the cold start */
+  def countColdStart(kind: String, memoryLimit: ByteSize): Unit = {
+    prewarmConfig
+      .filter { config =>
+        kind == config.exec.kind && memoryLimit == config.memoryLimit
+      }
+      .foreach { _ =>
+        val time = new SimpleDateFormat("yyyy-MM-dd-HH:mm").format(Calendar.getInstance().getTime)
+        val key = s"${kind},${memoryLimit.toMB},${time}"
+        coldStartCount.getOrElseUpdate(key, new AtomicInteger(0)).getAndIncrement()
 
 Review comment:
   Does this need AtomicInteger? Container allocation should happen in actor message processing, which is single threaded

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services