Improvements and finalization of dynamically resizable routers, replaces ActorPool. See 1557
* resize on nth message instead of always each message * improved pressure evaluation * more tests * documentation * removed ActorPool
This commit is contained in:
parent
8b71bf5bea
commit
19845d93e8
21 changed files with 591 additions and 1226 deletions
|
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package akka.docs.routing
|
||||
|
||||
import akka.routing.{ BasicNoBackoffFilter, SmallestMailboxSelector, DefaultActorPool }
|
||||
import akka.actor.{ ActorRef, Props, Actor }
|
||||
|
||||
//#testPool
|
||||
class TestPool extends Actor with DefaultActorPool with SmallestMailboxSelector with BasicNoBackoffFilter {
|
||||
|
||||
def capacity(delegates: Seq[ActorRef]) = 5
|
||||
protected def receive = _route
|
||||
def rampupRate = 0.1
|
||||
def selectionCount = 1
|
||||
def partialFill = true
|
||||
|
||||
def instance(defaults: Props) = context.actorOf(defaults.withCreator(new Actor {
|
||||
def receive = {
|
||||
case _ ⇒ // do something
|
||||
}
|
||||
}))
|
||||
}
|
||||
//#testPool
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package akka.docs.routing
|
||||
|
||||
import akka.actor.ActorRef
|
||||
|
||||
//#boundedCapacitor
|
||||
trait BoundedCapacitor {
|
||||
def lowerBound: Int
|
||||
def upperBound: Int
|
||||
|
||||
def capacity(delegates: Seq[ActorRef]): Int = {
|
||||
val current = delegates length
|
||||
var delta = _eval(delegates)
|
||||
val proposed = current + delta
|
||||
|
||||
if (proposed < lowerBound) delta += (lowerBound - proposed)
|
||||
else if (proposed > upperBound) delta -= (proposed - upperBound)
|
||||
|
||||
delta
|
||||
}
|
||||
|
||||
protected def _eval(delegates: Seq[ActorRef]): Int
|
||||
}
|
||||
//#boundedCapacitor
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2011 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package akka.docs.routing
|
||||
|
||||
import akka.routing.ActorPool
|
||||
import akka.actor.ActorRef
|
||||
|
||||
//#capacityStrategy
|
||||
trait CapacityStrategy {
|
||||
import ActorPool._
|
||||
|
||||
def pressure(delegates: Seq[ActorRef]): Int
|
||||
def filter(pressure: Int, capacity: Int): Int
|
||||
|
||||
protected def _eval(delegates: Seq[ActorRef]): Int =
|
||||
filter(pressure(delegates), delegates.size)
|
||||
}
|
||||
//#capacityStrategy
|
||||
|
|
@ -25,6 +25,17 @@ object RouterWithConfigExample extends App {
|
|||
}
|
||||
}
|
||||
//#config
|
||||
//#config-resize
|
||||
akka.actor.deployment {
|
||||
/router2 {
|
||||
router = round-robin
|
||||
resizer {
|
||||
lower-bound = 2
|
||||
upper-bound = 15
|
||||
}
|
||||
}
|
||||
}
|
||||
//#config-resize
|
||||
""")
|
||||
val system = ActorSystem("Example", config)
|
||||
//#configurableRouting
|
||||
|
|
@ -32,4 +43,10 @@ object RouterWithConfigExample extends App {
|
|||
"router")
|
||||
//#configurableRouting
|
||||
1 to 10 foreach { i ⇒ router ! Message(i) }
|
||||
|
||||
//#configurableRoutingWithResizer
|
||||
val router2 = system.actorOf(Props[ExampleActor].withRouter(FromConfig()),
|
||||
"router2")
|
||||
//#configurableRoutingWithResizer
|
||||
1 to 10 foreach { i ⇒ router2 ! Message(i) }
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ package akka.docs.routing
|
|||
|
||||
import akka.routing.RoundRobinRouter
|
||||
import akka.actor.{ ActorRef, Props, Actor, ActorSystem }
|
||||
import akka.routing.DefaultResizer
|
||||
|
||||
case class Message1(nbr: Int)
|
||||
|
||||
|
|
@ -31,4 +32,12 @@ object RoutingProgrammaticallyExample extends App {
|
|||
RoundRobinRouter(routees = routees)))
|
||||
//#programmaticRoutingRoutees
|
||||
1 to 6 foreach { i ⇒ router2 ! Message1(i) }
|
||||
|
||||
//#programmaticRoutingWithResizer
|
||||
val resizer = DefaultResizer(lowerBound = 2, upperBound = 15)
|
||||
val router3 = system.actorOf(Props[ExampleActor1].withRouter(
|
||||
RoundRobinRouter(resizer = Some(resizer))))
|
||||
//#programmaticRoutingWithResizer
|
||||
1 to 6 foreach { i ⇒ router3 ! Message1(i) }
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue