Created
November 28, 2011 13:48
-
-
Save t3hnar/1400453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.thenewmotion.chargenetwork.server.services.proto | |
import akka.actor._ | |
import akka.actor.Actor._ | |
import akka.routing._ | |
import akka.event.EventHandler | |
/** | |
* @author Yaroslav Klymko | |
*/ | |
object ActorPerf extends App { | |
val size = 10000 | |
val r = (0 until size).map { | |
x => | |
val nano = System.nanoTime() | |
actorOf(new MyActor).start() ! x | |
val spent = System.nanoTime() - nano | |
spent | |
} | |
val a = actorOf(new TestPool).start() | |
val r1 = (0 until size).map { | |
x => | |
val nano = System.nanoTime() | |
a ! x | |
val spent = System.nanoTime() - nano | |
spent | |
} | |
val a1 = actorOf(new MyActor).start() | |
val r2 = (0 until size).map { | |
x => | |
val nano = System.nanoTime() | |
a1 ! x | |
val spent = System.nanoTime() - nano | |
spent | |
} | |
Thread.sleep(15000) | |
Actor.registry.shutdownAll() | |
println("new " + (0L /: r)(_ + _) / size) | |
println("pool " + (0L /: r1)(_ + _) / size) | |
println("same " + (0L /: r2)(_ + _) / size) | |
class MyActor extends Actor { | |
protected def receive = { | |
case x: Int => | |
EventHandler.info(this, ">>> " + x) | |
// | |
// Thread.sleep(1) | |
(1 /: (0 to 10000))(_ * _) | |
EventHandler.info(this, "<<< " + x) | |
} | |
} | |
class TestPool extends Actor with DefaultActorPool | |
with BoundedCapacityStrategy | |
with MailboxPressureCapacitor | |
with SmallestMailboxSelector | |
with Filter | |
with RunningMeanBackoff | |
with BasicRampup { | |
def receive = _route | |
def lowerBound = 1 | |
def upperBound = 5 | |
def pressureThreshold = 1 | |
def partialFill = true | |
def selectionCount = 1 | |
def rampupRate = 0.1 | |
def backoffRate = 0.50 | |
def backoffThreshold = 0.50 | |
def instance = actorOf(new MyActor) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment