You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2017/09/21 14:15:13 UTC

[incubator-openwhisk] branch master updated: Remove "Thread.sleep" from log reading retries. (#2751)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d881fe1  Remove "Thread.sleep" from log reading retries. (#2751)
d881fe1 is described below

commit d881fe1a3af1178b06a38f4a4646d01558399491
Author: Markus Thömmes <ma...@me.com>
AuthorDate: Thu Sep 21 16:15:11 2017 +0200

    Remove "Thread.sleep" from log reading retries. (#2751)
    
    "Thread.sleep" unnecessarily blocks the Thread instead of scheduling the retry.
---
 .../whisk/core/containerpool/docker/DockerContainer.scala   |  8 ++++++--
 .../containerpool/docker/test/DockerContainerTests.scala    | 13 ++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
index 1534a66..7e07247 100644
--- a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
+++ b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
@@ -19,6 +19,9 @@ package whisk.core.containerpool.docker
 
 import java.nio.charset.StandardCharsets
 import java.time.Instant
+
+import akka.actor.ActorSystem
+
 import scala.concurrent.ExecutionContext
 import scala.concurrent.Future
 import scala.concurrent.duration._
@@ -68,6 +71,7 @@ object DockerContainer {
              dnsServers: Seq[String] = Seq(),
              name: Option[String] = None)(implicit docker: DockerApiWithFileAccess,
                                           runc: RuncApi,
+                                          as: ActorSystem,
                                           ec: ExecutionContext,
                                           log: Logging): Future[DockerContainer] = {
     implicit val tid = transid
@@ -133,6 +137,7 @@ object DockerContainer {
  */
 class DockerContainer(id: ContainerId, ip: ContainerIp)(implicit docker: DockerApiWithFileAccess,
                                                         runc: RuncApi,
+                                                        as: ActorSystem,
                                                         ec: ExecutionContext,
                                                         logger: Logging)
     extends Container
@@ -250,8 +255,7 @@ class DockerContainer(id: ContainerId, ip: ContainerIp)(implicit docker: DockerA
 
           if (retries > 0 && !isComplete && !isTruncated) {
             logger.info(this, s"log cursor advanced but missing sentinel, trying $retries more times")
-            Thread.sleep(logsRetryWait.toMillis)
-            readLogs(retries - 1)
+            akka.pattern.after(logsRetryWait, as.scheduler)(readLogs(retries - 1))
           } else {
             logFileOffset += rawLogBytes.position - rawLogBytes.arrayOffset
             Future.successful(formattedLogs)
diff --git a/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala b/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala
index d56371d..1451c5d 100644
--- a/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala
+++ b/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala
@@ -25,9 +25,7 @@ import java.time.Instant
 import scala.collection.mutable
 import scala.concurrent.Await
 import scala.concurrent.duration._
-import scala.concurrent.ExecutionContext.Implicits.global
 import scala.concurrent.Future
-
 import org.junit.runner.RunWith
 import org.scalamock.scalatest.MockFactory
 import org.scalatest.BeforeAndAfterEach
@@ -35,8 +33,7 @@ import org.scalatest.FlatSpec
 import org.scalatest.Inspectors._
 import org.scalatest.junit.JUnitRunner
 import org.scalatest.Matchers
-
-import common.StreamLogging
+import common.{StreamLogging, WskActorSystem}
 import spray.json._
 import whisk.common.LoggingMarkers._
 import whisk.common.LogMarker
@@ -53,7 +50,13 @@ import whisk.http.Messages
  * Unit tests for ContainerPool schedule
  */
 @RunWith(classOf[JUnitRunner])
-class DockerContainerTests extends FlatSpec with Matchers with MockFactory with StreamLogging with BeforeAndAfterEach {
+class DockerContainerTests
+    extends FlatSpec
+    with Matchers
+    with MockFactory
+    with StreamLogging
+    with BeforeAndAfterEach
+    with WskActorSystem {
 
   override def beforeEach() = {
     stream.reset()

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].