By Alvin Alexander. Last updated: June 6, 2016
A Scala Akka 2.0 Actor "ping pong" example:
case object Run case object Msg class Destination extends Actor { def receive = { case Msg ⇒ sender ! Msg } } class Client( actor: ActorRef, latch: CountDownLatch, repeat: Long) extends Actor { var sent = 0L var received = 0L def receive = { case Msg ⇒ received += 1 if (sent < repeat) { actor ! Msg sent += 1 } else if (received >= repeat) { latch.countDown() } case Run ⇒ for (i ← 0L until math.min(1000L, repeat)) { actor ! Msg sent += 1 } } }
From the letitcrash.com website: The purpose of the used micro benchmark is to see how throughput of message send and receive is affected by increasing number of concurrent, active, actors sharing the same dispatcher. Pairs of actors send messages to each other, classical ping-pong. Load is increased by adding more pairs of actors that are processing messages in parallel with other actors.