You have one single LoginActor that will processes the requests sequentially. Would it be possible to have more than one of that actor? E.g. using a router Pool?
The LoginActor is doing blocking database calls, as far as I can see. You should manage this blocking carefully <http://doc.akka.io/docs/akka/2.3.9/general/actor-systems.html#Blocking_Needs_Careful_Management>, by running it on a dedicated dispatcher. Something like this val authPool = context.actorOf(new RoundRobinPool(20).props(Props[LoginActor].withDispatcher("blocking-io-dispatcher")), "authPool") where the dispatcher is defined in config: # A dispatcher tuned for performing blocking IO blocking-io-dispatcher { executor = "thread-pool-executor" thread-pool-executor { core-pool-size-min = 20 # set this to same value as number of connections in the database connection pool core-pool-size-max = 20 # set this to same value as above } throughput = 1 } You might be interested in Reactive Slick, i.e. Slick 3.0 <http://slick.typesafe.com/news/2015/02/20/slick-3.0.0-RC1-released.html>, to avoid the blocking. Regards, Patrik On Tue, Mar 24, 2015 at 6:33 PM, Robert Barreiro <[email protected]> wrote: > Helo guys. > > I'm new with Scala and Akka. I'm trying to build a small payment > authorization service using Scala + Akka + Spray. > I've started to write a small piece of code with just one operation and I > wanted to validate the code and the performance. I'm using ab to test it > and I'm having trouble to get a good performance, right now having only 7 > transactions per second which I think is very slow. > > I'm pretty sure I'm doing something wrong, so I wanted to ask you guys if > you see something wrong with my code. > Here are the details: > > > GatewayKernel: > > class RestInterface extends HttpServiceActor { > > import context.dispatcher > import akka.pattern.{ask, pipe} > > implicit val timeout = Timeout(10 seconds) > val authActor = context.actorOf(Props[LoginActor]) > > def receive = runRoute { > pathPrefix("api") { > path("login") { > post { > detach() { > entity(as[Login]) { login => requestContext => > val responderActor = createAuthResponder(requestContext) > authActor.ask(login) pipeTo responderActor > } > } > } > } > }~ > pathPrefix("api") { // just for testing > path("ping") { > get { > complete { "pong" } > } > } > } > } > > def createAuthResponder(requestContext:RequestContext) = { > context.actorOf(Props(new AuthProcessor(requestContext, authActor))) > } > > } > > > > And the definition for LoginActor is very simple: > > > class LoginActor extends Actor with ActorLogging { > > > def receive = { > > case Login(username, password, terminalId, device_serial) => { > > sender ! handleLogin(username, password, terminalId, device_serial > ) > > } > > } > > > > def handleLogin(username: String, password: String, terminalId: Int, > device_serial: Option[String]) { > > dbo withSession { implicit session => > > val userInfo = tableTerminalUser.filter( > > tu => tu.userName === username && tu.terminalId === terminalId). > map( > > tu => (tu.passHash, tu.status, tu.expires)).run.headOption > > > if ( !userInfo.isEmpty ) { > > // Check user status > > val status = userInfo.get._2 > > if (status != 1) { // TODO: Move somewhere else > > sender ! new ResponseError(-1001, "User account is inactive") > > } > > else{ > > // Check password > > val passHash = userInfo.get._1 > > > > if (PasswordUtil.validatePassword(password, passHash)) { > > sender ! new LoginOkResponse(0, "a23bce005432a394") > > } > > else { > > sender ! new ResponseError(-1001, "Invalid user name or > password") > > } > > } > > } > > else { > > sender ! new ResponseError(-1000, "Invalid user name or password") > > } > > } > > } > > } > > > I'm also using Slick to db access. > As you can see it's very simple. > > Here is what you can see with ab: > > Benchmarking localhost (be patient) > Completed 100 requests > Completed 200 requests > Completed 300 requests > Completed 400 requests > Completed 500 requests > Finished 500 requests > > > Server Software: > Server Hostname: localhost > Server Port: 5000 > > Document Path: /api/login > Document Length: 50 bytes > > Concurrency Level: 20 > Time taken for tests: 106.394 seconds > Complete requests: 500 > Failed requests: 0 > Write errors: 0 > Total transferred: 86500 bytes > Total POSTed: 113000 > HTML transferred: 25000 bytes > Requests per second: 4.70 [#/sec] (mean) > Time per request: 4255.766 [ms] (mean) > Time per request: 212.788 [ms] (mean, across all concurrent requests) > Transfer rate: 0.79 [Kbytes/sec] received > 1.04 kb/s sent > 1.83 kb/s total > > Connection Times (ms) > min mean[+/-sd] median max > Connect: 0 0 0.4 0 4 > Processing: 364 4180 724.1 4219 5432 > Waiting: 363 4180 724.1 4219 5432 > Total: 367 4180 723.9 4219 5432 > > Percentage of the requests served within a certain time (ms) > 50% 4219 > 66% 4531 > 75% 4749 > 80% 4822 > 90% 5099 > 95% 5194 > 98% 5238 > 99% 5402 > 100% 5432 (longest request) > > > In this case less than 7 TPS. > Thanks for your help. > > > Regards. > > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: > http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- Patrik Nordwall Typesafe <http://typesafe.com/> - Reactive apps on the JVM Twitter: @patriknw -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
