Commit 75c91e37 authored by neverlord's avatar neverlord

benchmark update

parent e6d6a30b
import akka.actor.{ Props, Actor, ActorRef, ActorSystem }
import com.typesafe.config.ConfigFactory
import Console.println
case object Done
case class Error(msg: String)
case class KickOff(value: Int)
case class Ping(value: Int)
case class Pong(value: Int)
case class AddPong(path: String)
case object Hello
case object Olleh
case class RunClient(pongs: List[ActorRef], numPings: Int)
object global {
val latch = new java.util.concurrent.CountDownLatch(1)
}
class PingActor(parent: ActorRef, pong: ActorRef) extends Actor {
def receive = {
case Pong(0) => {
//println(parent + " ! Done")
parent ! Done
context.stop(self)
}
case Pong(value) => {
sender ! Ping(value - 1)
}
case KickOff(value) => {
//println("PingActor::KickOff " + value)
pong ! Ping(value)
}
}
}
class ServerActor(system: ActorSystem) extends Actor {
var pongs = List[ActorRef]()
def receive = {
case Ping(value) => {
sender ! Pong(value)
}
case AddPong(path) => {
//println("add actor " + path)
if (pongs.exists((x) => x.path == path)) {
sender ! Ok
} else {
val pong = system.actorFor(path)
pong ! Hello
pongs = pong :: pongs
sender ! Ok
}
}
case KickOff(value) => {
val client = sender
//println("KickOff(" + value + ") from " + client)
pongs.foreach((x) => context.actorOf(Props(new PingActor(client, x))) ! KickOff(value))
}
case Hello => {
sender ! Olleh
}
case Olleh => {
//println("Olleh from " + sender)
}
}
}
class ClientActor extends Actor {
import context._
var left: Int = 0
def collectDoneMessages: Receive = {
case Done => {
//println("Done")
if (left == 1) {
global.latch.countDown
context.stop(self)
} else {
left = left - 1
}
}
case x => {
// ignore any other message
}
}
def collectOkMessages(pongs: List[ActorRef], numPings: Int): Receive = {
case Ok => {
//println("Ok")
if (left == 1) {
left = pongs.length * (pongs.length - 1)
pongs.foreach(x => x ! KickOff(numPings))
become(collectDoneMessages)
} else {
left = left - 1
}
}
}
def receive = {
case RunClient(pongs, numPings) => {
pongs.foreach(x => pongs.foreach(y => if (x != y) {
x ! AddPong(y.path.toString)
}))
left = pongs.length * (pongs.length - 1)
become(collectOkMessages(pongs, numPings))
}
}
}
object distributedClientApp {
def main(args: Array[String]) = {
val system = ActorSystem("benchmark", ConfigFactory.load.getConfig("benchmark"))
var numPings: Int = 0
var pongs = List[ActorRef]()
val NumPings = "num_pings=([0-9]+)".r
args.foreach(arg => arg match {
case NumPings(num) => {
numPings = num.toInt
}
case _ => {
//println("add actor " + arg)
pongs = system.actorFor(arg) :: pongs
}
})
system.actorOf(Props[ClientActor]) ! RunClient(pongs, numPings)
global.latch.await
System.exit(0)
}
}
object distributedServerApp {
def main(args: Array[String]) = {
val sysName = if (args.length > 0) args(0) else "pongServer"
val system = ActorSystem(sysName, ConfigFactory.load.getConfig("pongServer"))
val pong = system.actorOf(Props(new ServerActor(system)), "pong")
//val subSystem = ActorSystem(sysName + "Client", ConfigFactory.load.getConfig("benchmark"))
//val pong = system.actorOf(Props(new ServerActor(subSystem)), "pong")
}
}
import scala.actors.Actor
import scala.actors.Actor._
import Console.println
case object KickOff
case class Ping(value: Int)
case class Pong(value: Int)
object global {
val latch = new java.util.concurrent.CountDownLatch(1)
}
class PingActor(num: Int, pong: akka.actor.ActorRef) extends akka.actor.Actor {
def receive = {
case Pong(`num`) => {
//println("Received final pong")
global.latch.countDown
context.stop(self)
}
case Pong(value) => sender ! Ping(value + 1)
case KickOff => pong ! Ping(0)
}
}
class PongActor extends akka.actor.Actor {
def receive = {
case Ping(value) => sender ! Pong(value)
}
}
object pingApp {
def main(args: Array[String]) = {
if (args.size != 3) {
println("usage: pingApp (host) (port) (num pings)")
println(" connects to pong-service@(host):(port)")
System.exit(1)
}
val host = args(0)
val port = args(1).toInt
val numPings = args(2).toInt
val pong = remote.actorFor("pong-service", host, port)
val ping = system.actorOf(Props(new PingActor(numPings, pong)), name="ping")
remote.start("localhost", 64002).register("ping-service", ping)
ping ! KickOff
global.latch.await
remote.shutdown
System.exit(0)
}
}
object pongApp {
def main(args: Array[String]) = {
if (args.size != 1) {
println("usage: pongApp (port)")
println(" binds pong-service to given port")
System.exit(1)
}
remote.start("localhost", args(0).toInt)
.register("pong-service",
actorOf(new PongActor).start)
}
}
#benchmark {
# include "common"
#
# akka {
# loglevel = ERROR
# remote {
# netty.port = 0
# untrusted-mode = on
# transport = "akka.remote.netty.NettyRemoteTransport"
# }
# }
#}
benchmark {
akka {
loglevel = ERROR
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
netty {
hostname = "127.0.0.1"
port = 0
}
}
}
}
pongServer {
akka {
loglevel = ERROR
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
netty {
hostname = "127.0.0.1"
port = 4422
}
}
}
}
...@@ -76,15 +76,15 @@ inline option<int> _2i(std::string const& str) ...@@ -76,15 +76,15 @@ inline option<int> _2i(std::string const& str)
void usage() void usage()
{ {
cout << "Running in server mode:" << endl cout << "Running in server mode:" << endl
<< " mode=server " << endl << " mode=server " << endl
<< " --port=NUM publishes an actor at port NUM" << endl << " --port=NUM publishes an actor at port NUM" << endl
<< " -p NUM alias for --port=NUM" << endl << " -p NUM alias for --port=NUM" << endl
<< endl << endl
<< endl << endl
<< "Running the benchmark:" << endl << "Running the benchmark:" << endl
<< " mode=benchmark run the benchmark, connect to any number"<< endl << " mode=benchmark run the benchmark, connect to any number" << endl
<< " of given servers, use HOST:PORT syntax" << endl << " of given servers, use HOST:PORT syntax" << endl
<< " num_pings=NUM run benchmark with NUM messages per node"<< endl << " num_pings=NUM run benchmark with NUM messages per node" << endl
<< endl << endl
<< " example: mode=benchmark 192.168.9.1:1234 " << " example: mode=benchmark 192.168.9.1:1234 "
"192.168.9.2:1234 " "192.168.9.2:1234 "
...@@ -92,7 +92,7 @@ void usage() ...@@ -92,7 +92,7 @@ void usage()
<< endl << endl
<< endl << endl
<< "Shutdown servers:" << endl << "Shutdown servers:" << endl
<< " mode=shutdown shuts down any number of given servers" << endl << " mode=shutdown shuts down any number of given servers" << endl
<< endl << endl
<< endl << endl
<< "Miscellaneous:" << endl << "Miscellaneous:" << endl
......
benchmarks/ActorCreation.scala benchmarks/ActorCreation.scala
benchmarks/Distributed.scala
benchmarks/MailboxPerformance.scala benchmarks/MailboxPerformance.scala
benchmarks/Matching.scala benchmarks/Matching.scala
benchmarks/MixedCase.scala benchmarks/MixedCase.scala
benchmarks/PingPong.scala
benchmarks/actor_creation.cpp benchmarks/actor_creation.cpp
benchmarks/actor_creation.erl benchmarks/actor_creation.erl
benchmarks/distributed.cpp benchmarks/distributed.cpp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment