Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Actor benchmark
package benchmark
import akka.actor._
object ActorBenchmark {
class IntermediateMapper(target: ActorRef) extends Actor {
var state: Wrapper = Wrapper(0,0)
def receive = {
case (w:Wrapper) => {
state = state + w
target ! state
}
}
}
class TerminalActor(onFinish: =>Unit, finishCount: Long) extends Actor {
var count: Long = 0L
var lastWrapper: Wrapper = Wrapper(0,0)
def receive = {
case (w:Wrapper) => {
lastWrapper = w
count += 1
if (count == finishCount) {
onFinish
}
}
}
}
def sendReceiveTest = {
val system = ActorSystem("sendReceiveTest")
var finishTime: Long = 0
val terminalActor = system.actorOf(Props(new TerminalActor({finishTime = System.currentTimeMillis()}, finishCount = 8*1024*1024)))
val intermediateActor = system.actorOf(Props(new IntermediateMapper(terminalActor)))
val startTime: Long = System.currentTimeMillis()
var i=0;
while (i < 8*1024*1024) {
intermediateActor ! Wrapper(i,-i)
i += 1
}
Thread.sleep(10000)
println("Start time: " + startTime)
println("End time: " + finishTime)
println("Delta: " + (finishTime - startTime))
system.shutdown
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment