From 13ab46b5a8049b62c3f35ee22107bd10528f6173 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Wed, 29 Jan 2014 14:53:46 -0500 Subject: [PATCH] Updated logging during searching to be less annoying. Changed the concurrent engine to use more actors, additionally made it use a different type of router for efficiency since not all images in a directory will take the same amount of time to process. --- .../com/sothr/imagetools/ConcurrentEngine.scala | 16 ++++++++-------- .../com/sothr/imagetools/SequentialEngine.scala | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala b/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala index 81ec0bf..3424e57 100644 --- a/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala +++ b/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala @@ -2,7 +2,7 @@ package com.sothr.imagetools import java.io.File import akka.actor.{Actor, ActorSystem, Props, ActorLogging} -import akka.routing.{Broadcast, RoundRobinRouter} +import akka.routing.{Broadcast, SmallestMailboxRouter} import akka.event.Logging import akka.pattern.ask import akka.util.Timeout @@ -51,7 +51,8 @@ class ConcurrentEngine extends Engine with grizzled.slf4j.Logging { case false => debug("Still Processing") //sleep thread - val future = Future { blocking(Thread.sleep(5000L)); "done" } + Thread.sleep(5000L) + //val future = Future { blocking(Thread.sleep(5000L)); "done" } } } val f = engineController ? EngineGetProcessingResults @@ -74,7 +75,9 @@ class ConcurrentEngine extends Engine with grizzled.slf4j.Logging { var similarCount = 0 for (rootImage <- images) { if (!ignoreSet.contains(rootImage)) { - info(s"Processed ${processedCount}/${images.length - ignoreSet.size} About ${images.length - processedCount} images to go") + if (processedCount % 25 == 0) { + info(s"Processed ${processedCount}/${images.length - ignoreSet.size} About ${images.length - processedCount} images to go") + } debug(s"Looking for images similar to: ${rootImage.imagePath}") ignoreSet += rootImage val similarImages = new MutableList[Image]() @@ -104,7 +107,7 @@ class ConcurrentEngine extends Engine with grizzled.slf4j.Logging { class ConcurrentEngineController extends Actor with ActorLogging { val imageCache = AppConfig.cacheManager.getCache("images") val numOfRouters = 10 - val router = context.actorOf(Props[ConcurrentEngineActor].withRouter(RoundRobinRouter(nrOfInstances = numOfRouters))) + val router = context.actorOf(Props[ConcurrentEngineActor].withRouter(SmallestMailboxRouter(nrOfInstances = numOfRouters))) var images:MutableList[Image] = new MutableList[Image]() var toProcess = 0 @@ -146,9 +149,6 @@ class ConcurrentEngineController extends Actor with ActorLogging { } } - /* - * - */ def requestWrapup() = { router ! Broadcast(EngineNoMoreFiles) } @@ -197,7 +197,7 @@ class ConcurrentEngineActor extends Actor with ActorLogging { case command:EngineProcessFile => processFile(command) case EngineNoMoreFiles => finishedProcessingFiles() case EngineActorReactivate => ignoreMessages = false - case _ => log.info("received unknown message") + case _ => log.info("received unknown message") } def processFile(command:EngineProcessFile) = { diff --git a/src/main/scala/com/sothr/imagetools/SequentialEngine.scala b/src/main/scala/com/sothr/imagetools/SequentialEngine.scala index bb902ab..091c16a 100644 --- a/src/main/scala/com/sothr/imagetools/SequentialEngine.scala +++ b/src/main/scala/com/sothr/imagetools/SequentialEngine.scala @@ -48,7 +48,9 @@ class SequentialEngine extends Engine with Logging { var similarCount = 0 for (rootImage <- images) { if (!ignoreSet.contains(rootImage)) { - info(s"Processed ${processedCount}/${images.length - ignoreSet.size} About ${images.length - processedCount} images to go") + if (processedCount % 25 == 0) { + info(s"Processed ${processedCount}/${images.length - ignoreSet.size} About ${images.length - processedCount} images to go") + } debug(s"Looking for images similar to: ${rootImage.imagePath}") ignoreSet += rootImage val similarImages = new mutable.MutableList[Image]()