+act #13004 Adding TailChopping router
This commit is contained in:
parent
b88c964bd4
commit
1658f96862
8 changed files with 631 additions and 27 deletions
|
|
@ -61,6 +61,8 @@ import akka.routing.ScatterGatherFirstCompletedGroup;
|
|||
import akka.routing.ScatterGatherFirstCompletedPool;
|
||||
import akka.routing.BalancingPool;
|
||||
import akka.routing.SmallestMailboxPool;
|
||||
import akka.routing.TailChoppingGroup;
|
||||
import akka.routing.TailChoppingPool;
|
||||
|
||||
//#imports2
|
||||
|
||||
|
|
@ -275,39 +277,66 @@ public class RouterDocTest {
|
|||
"router20");
|
||||
//#scatter-gather-group-2
|
||||
|
||||
//#consistent-hashing-pool-1
|
||||
//#tail-chopping-pool-1
|
||||
ActorRef router21 =
|
||||
getContext().actorOf(FromConfig.getInstance().props(
|
||||
Props.create(Worker.class)), "router21");
|
||||
//#tail-chopping-pool-1
|
||||
|
||||
//#tail-chopping-pool-2
|
||||
FiniteDuration within3 = FiniteDuration.create(10, TimeUnit.SECONDS);
|
||||
FiniteDuration interval = FiniteDuration.create(20, TimeUnit.MILLISECONDS);
|
||||
ActorRef router22 =
|
||||
getContext().actorOf(new TailChoppingPool(5, within3, interval).props(
|
||||
Props.create(Worker.class)), "router22");
|
||||
//#tail-chopping-pool-2
|
||||
|
||||
//#tail-chopping-group-1
|
||||
ActorRef router23 =
|
||||
getContext().actorOf(FromConfig.getInstance().props(), "router23");
|
||||
//#tail-chopping-group-1
|
||||
|
||||
//#tail-chopping-group-2
|
||||
FiniteDuration within4 = FiniteDuration.create(10, TimeUnit.SECONDS);
|
||||
FiniteDuration interval2 = FiniteDuration.create(20, TimeUnit.MILLISECONDS);
|
||||
ActorRef router24 =
|
||||
getContext().actorOf(new TailChoppingGroup(paths, within4, interval2).props(),
|
||||
"router24");
|
||||
//#tail-chopping-group-2
|
||||
|
||||
//#consistent-hashing-pool-1
|
||||
ActorRef router25 =
|
||||
getContext().actorOf(FromConfig.getInstance().props(Props.create(Worker.class)),
|
||||
"router21");
|
||||
"router25");
|
||||
//#consistent-hashing-pool-1
|
||||
|
||||
//#consistent-hashing-pool-2
|
||||
ActorRef router22 =
|
||||
ActorRef router26 =
|
||||
getContext().actorOf(new ConsistentHashingPool(5).props(
|
||||
Props.create(Worker.class)), "router22");
|
||||
Props.create(Worker.class)), "router26");
|
||||
//#consistent-hashing-pool-2
|
||||
|
||||
//#consistent-hashing-group-1
|
||||
ActorRef router23 =
|
||||
getContext().actorOf(FromConfig.getInstance().props(), "router23");
|
||||
ActorRef router27 =
|
||||
getContext().actorOf(FromConfig.getInstance().props(), "router27");
|
||||
//#consistent-hashing-group-1
|
||||
|
||||
//#consistent-hashing-group-2
|
||||
ActorRef router24 =
|
||||
getContext().actorOf(new ConsistentHashingGroup(paths).props(), "router24");
|
||||
ActorRef router28 =
|
||||
getContext().actorOf(new ConsistentHashingGroup(paths).props(), "router28");
|
||||
//#consistent-hashing-group-2
|
||||
|
||||
//#resize-pool-1
|
||||
ActorRef router25 =
|
||||
ActorRef router29 =
|
||||
getContext().actorOf(FromConfig.getInstance().props(
|
||||
Props.create(Worker.class)), "router25");
|
||||
Props.create(Worker.class)), "router29");
|
||||
//#resize-pool-1
|
||||
|
||||
//#resize-pool-2
|
||||
DefaultResizer resizer = new DefaultResizer(2, 15);
|
||||
ActorRef router26 =
|
||||
ActorRef router30 =
|
||||
getContext().actorOf(new RoundRobinPool(5).withResizer(resizer).props(
|
||||
Props.create(Worker.class)), "router26");
|
||||
Props.create(Worker.class)), "router30");
|
||||
//#resize-pool-2
|
||||
|
||||
public void onReceive(Object msg) {}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ The routing logic shipped with Akka are:
|
|||
* ``akka.routing.SmallestMailboxRoutingLogic``
|
||||
* ``akka.routing.BroadcastRoutingLogic``
|
||||
* ``akka.routing.ScatterGatherFirstCompletedRoutingLogic``
|
||||
* ``akka.routing.TailChoppingRoutingLogic``
|
||||
* ``akka.routing.ConsistentHashingRoutingLogic``
|
||||
|
||||
We create the routees as ordinary child actors wrapped in ``ActorRefRoutee``. We watch
|
||||
|
|
@ -370,6 +371,40 @@ ScatterGatherFirstCompletedGroup defined in code:
|
|||
.. includecode:: code/docs/jrouting/RouterDocTest.java
|
||||
:include: paths,scatter-gather-group-2
|
||||
|
||||
TailChoppingPool and TailChoppingGroup
|
||||
--------------------------------------
|
||||
|
||||
The TailChoppingRouter will first send the message to one, randomly picked, routee
|
||||
and then after a small delay to to a second routee (picked randomly from the remaining routees) and so on.
|
||||
It waits for first reply it gets back and forwards it back to original sender. Other replies are discarded.
|
||||
|
||||
The goal of this router is to decrease latency by performing redundant queries to multiple routees, assuming that
|
||||
one of the other actors may still be faster to respond than the initial one.
|
||||
|
||||
This optimisation was described nicely in a blog post by Peter Bailis:
|
||||
`Doing redundant work to speed up distributed queries <http://www.bailis.org/blog/doing-redundant-work-to-speed-up-distributed-queries/>`_.
|
||||
|
||||
TailChoppingPool defined in configuration:
|
||||
|
||||
.. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-tail-chopping-pool
|
||||
|
||||
.. includecode:: code/docs/jrouting/RouterDocTest.java#tail-chopping-pool-1
|
||||
|
||||
TailChoppingPool defined in code:
|
||||
|
||||
.. includecode:: code/docs/jrouting/RouterDocTest.java#tail-chopping-pool-2
|
||||
|
||||
TailChoppingGroup defined in configuration:
|
||||
|
||||
.. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-tail-chopping-group
|
||||
|
||||
.. includecode:: code/docs/jrouting/RouterDocTest.java#tail-chopping-group-1
|
||||
|
||||
TailChoppingGroup defined in code:
|
||||
|
||||
.. includecode:: code/docs/jrouting/RouterDocTest.java
|
||||
:include: paths,tail-chopping-group-2
|
||||
|
||||
ConsistentHashingPool and ConsistentHashingGroup
|
||||
------------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue