From ff6e708ce9c3b9acd3555dff8b9e35c72a1e9816 Mon Sep 17 00:00:00 2001 From: James Earl Douglas Date: Tue, 11 Sep 2012 17:42:20 -0700 Subject: [PATCH] add cyclic router and more threads --- spray-can/src/main/resources/akka.conf | 10 +++++++++- spray-can/src/main/scala/scamper/Scamper.scala | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spray-can/src/main/resources/akka.conf b/spray-can/src/main/resources/akka.conf index 7cad7a8..f4ea64d 100644 --- a/spray-can/src/main/resources/akka.conf +++ b/spray-can/src/main/resources/akka.conf @@ -7,6 +7,14 @@ akka { event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] event-handler-level = "DEBUG" # Options: ERROR, WARNING, INFO, DEBUG + + spray-root-service { + executor = "fork-join-executor" + fork-join-executor { + parallelism-factor = 24 + parallelism-max = 24 + } + } } # spray-can configuration @@ -18,7 +26,7 @@ spray-can { # service-actor-id = "spray-root-service" # timeout-actor-id = "spray-root-service" # idle-timeout = 10000 - request-timeout = 5000 + request-timeout = 15000 } } diff --git a/spray-can/src/main/scala/scamper/Scamper.scala b/spray-can/src/main/scala/scamper/Scamper.scala index 11f2605..e223665 100644 --- a/spray-can/src/main/scala/scamper/Scamper.scala +++ b/spray-can/src/main/scala/scamper/Scamper.scala @@ -4,6 +4,8 @@ import org.slf4j.LoggerFactory import akka.actor.Actor import akka.actor.Supervisor +import akka.routing.Routing +import akka.routing.CyclicIterator import akka.config.Supervision.OneForOneStrategy import akka.config.Supervision.Permanent import akka.config.Supervision.Supervise @@ -19,7 +21,13 @@ object Boot extends App { val mainModule = new ScamperService {} - val httpService = Actor.actorOf(new HttpService(mainModule.scamperService)) + val scamperActors = for { + _ <- 1 to 24 + val actor = Actor.actorOf[ScamperActor] + _ = actor.start + } yield actor + + val httpService = Routing.loadBalancerActor(new CyclicIterator(scamperActors)) val rootService = Actor.actorOf(new SprayCanRootService(httpService)) val sprayCanServer = Actor.actorOf(new HttpServer()) @@ -32,6 +40,8 @@ object Boot extends App { Supervise(sprayCanServer, Permanent)))) } +class ScamperActor extends HttpService((new ScamperService {}).scamperService) + trait ScamperService extends Directives { val scamperService = {