Browse Source

Added some logic to limit the number of heavy threads produced and used by the concurrent engine.

master
Drew Short 11 years ago
parent
commit
d561199300
  1. 16
      src/main/scala/com/sothr/imagetools/ConcurrentEngine.scala
  2. 3
      src/main/scala/com/sothr/imagetools/Engine.scala

16
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]

3
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.

Loading…
Cancel
Save