Skip to content

Instantly share code, notes, and snippets.

@stucchio
Created September 11, 2014 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stucchio/fbc29e84f68817b0a798 to your computer and use it in GitHub Desktop.
Save stucchio/fbc29e84f68817b0a798 to your computer and use it in GitHub Desktop.
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