On Monday, 22 October 2012 at 07:11, Sachin wrote:
Hi All,
I have written a small application to see if the scheduled messages are arriving in time (in other words how is the akka's time accuracy in scheduling messages?). When I run the following application, I was expecting 25 messages to arrive in 2500 milliseconds (a message is sent every 100 milliseconds). But I do not see more than 20 messages processed and after 2500 milliseconds, my application exits. I am puzzled about missed messages. Either scheduler is not timely sending the messages or those actors are not processed in time. So my questions are:
1. Am I making any wrong assumption?
2. How can I fix this (may be by configuring scheduler's tick-duration or tick-per-second)?
Any help regarding this is highly appreciated. Please see the code and result log below.
Thanks
Sachin
Code:
------------------------------------------------------------------------------------------------------------
import akka.actor._
import akka.util.duration._
case class DetectionTick
class DetectionActor extends Actor {
var count = 0
def receive = {
case DetectionTick =>
println("Tick received " + count)
count += 1
}
}
object detectiontick extends App {
val system = ActorSystem("detectiontick")
val detectionActor = system.actorOf(Props[DetectionActor], "detectionactor")
val cancellable = system.scheduler.schedule(0 milliseconds, 100 milliseconds, detectionActor, DetectionTick)
var StartTime = System.currentTimeMillis()
var EndTime = System.currentTimeMillis()
var timetaken = EndTime - StartTime
println("Start Time = " + StartTime)
while (true) {
EndTime = System.currentTimeMillis()
timetaken = EndTime - StartTime
if(timetaken > 2500) {
println("Time taken = " + timetaken)
println("End Time = " + EndTime)
cancellable.cancel()
exit
}
}
}
Output:
------------------------------------------------------------------------------------------------------------
$ java -cp /users/tools/akka-2.0.3/lib/scala-library.jar:/users/tools/akka-2.0.3/lib/akka/akka-actor-2.0.3.jar:/users/tools/akka-2.0.3/lib/akka/config-0.3.1.jar:. detectiontick
Start Time = 1350881825940
Tick received 0
Tick received 1
Tick received 2
Tick received 3
Tick received 4
Tick received 5
Tick received 6
Tick received 7
Tick received 8
Tick received 9
Tick received 10
Tick received 11
Tick received 12
Tick received 13
Tick received 14
Tick received 15
Tick received 16
Tick received 17
Tick received 18
Tick received 19
Time taken = 2501
End Time = 1350881828441
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> 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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
On Tuesday, 23 October 2012 at 18:06, Sachin wrote:
Hi Björn Antonsson,Thank you for the information. I will certainly try 2.1-RC1 version. I agree that having a busy wait will lead to actor not able to process the message. But I was assuming that actor may run on another thread, which was a wrong assumption.
Thanks for correcting me, I actually meant to say tick-per-second.
RegardsSachin