diff --git a/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala b/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala index f8c5527..3936296 100644 --- a/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala +++ b/src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala @@ -109,7 +109,13 @@ case object EngineActorReactivate class ConcurrentEngineProcessingController extends Actor with ActorLogging { val imageCache = AppConfig.cacheManager.getCache("images") - val numOfRouters = PropertiesService.get(PropertiesEnum.ConcurrentProcessingLimit.toString).toInt + val numOfRouters = { + val max = PropertiesService.get(PropertiesEnum.ConcurrentProcessingLimit.toString).toInt + val processors = Runtime.getRuntime.availableProcessors() + var threads = 0 + if (processors > max) threads = max else if (processors > 1) threads = processors - 1 else threads = 1 + threads + } val router = context.actorOf(Props[ConcurrentEngineProcessingActor].withRouter(SmallestMailboxRouter(nrOfInstances = numOfRouters))) var images:mutable.MutableList[Image] = new mutable.MutableList[Image]() @@ -228,7 +234,13 @@ case object EngineActorCompareImagesFinished class ConcurrentEngineSimilarityController extends Actor with ActorLogging { val imageCache = AppConfig.cacheManager.getCache("images") - val numOfRouters = PropertiesService.get(PropertiesEnum.ConcurrentSimiliartyLimit.toString).toInt + val numOfRouters = { + val max = PropertiesService.get(PropertiesEnum.ConcurrentSimiliartyLimit.toString).toInt + val processors = Runtime.getRuntime.availableProcessors() + var threads = 0 + if (processors > max) threads = max else if (processors > 1) threads = processors - 1 else threads = 1 + threads + } val router = context.actorOf(Props[ConcurrentEngineSimilarityActor].withRouter(SmallestMailboxRouter(nrOfInstances = numOfRouters))) val allSimilarImages = new mutable.MutableList[SimilarImages] diff --git a/src/main/scala/com/sothr/imagetools/Engine.scala b/src/main/scala/com/sothr/imagetools/Engine.scala index aaeaa8a..6edff72 100644 --- a/src/main/scala/com/sothr/imagetools/Engine.scala +++ b/src/main/scala/com/sothr/imagetools/Engine.scala @@ -1,10 +1,7 @@ package com.sothr.imagetools import com.sothr.imagetools.image.{SimilarImages, ImageFilter, Image} -import scala.collection.mutable -import java.io.File import grizzled.slf4j.Logging -import net.sf.ehcache.Element /** * Created by drew on 1/26/14.