akka typed actor, slow "ask" with time exponentially increasing by the number of messages

70 views
Skip to first unread message

Kostas kougios

unread,
Aug 24, 2017, 11:56:35 AM8/24/17
to Akka User List
Hi, I got this fairly simple actor:

private def actor(state: Option[R], calc: () => Future[R]): Actor.Immutable[Message] = Actor.immutable[Message] {
(_, msg) =>
msg match {
case Get(replyTo) =>
state match {
case Some(f) =>
replyTo ! f
Actor.same
case None =>
val f = calc().awaitFor(maxWaitForFuture)
replyTo ! f
actor(Some(f), calc)
}
case Flush =>
actor(None, calc)
}
}

There is a blocking calc().awaitFor call, but that's not my concern right now. The actual calc returns a Future that just increases an integer, nothing more.

I have a test case for it where I send it 400 Get(--) messages using the ask pattern, i.e. actor ? Get(_) . It takes 5 seconds for the test to run. This seems too long for me. My calc() method just increases an integer (it is just a test).
More weirdly when I increase the messages to 800, the time it takes is above 20 secs!!!

I did a bit of profiling, 45% of the time is spend on
akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick()

I saw the src code and it seems it sleeps a bit there conditionally.

How can I debug this slowness?

Kostas kougios

unread,
Aug 25, 2017, 4:09:46 AM8/25/17
to Akka User List
Did a quick test commenting out the blocking .awaitFor(). So there was no blocking call. But still it is too slow.

Johan Andrén

unread,
Sep 1, 2017, 11:48:48 AM9/1/17
to Akka User List
400 asks in 5 seconds should be nowhere near the number of asks/request-responses you can run through a single typed actor. Likely something in your logic or in how you measure is not quite right. 
As a reference, with a naive ping-pong test I can do around ~170 asks per ms on my machine.

Profiler showing the scheduler as cpu hotspot means your system isn't really doing anything.

If you want more help, please share the complete microbenchmark.

--
Johan
Akka Team

Konstantinos Kougios

unread,
Sep 18, 2017, 8:15:41 AM9/18/17
to akka...@googlegroups.com
It seems the slowdown was due to scalatest futureValue implicit. When I replaced it with Await.result(), the tests run fast.
--
>>>>>>>>>> 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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/sV4lS4AS4sg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages