Merge pull request #1776 from akka/wip-3663-balancing-disp-patriknw
+act #3663 Package BalancingDispatcher for usage in router pool
This commit is contained in:
commit
d4cce379ce
22 changed files with 140 additions and 47 deletions
|
|
@ -4,22 +4,27 @@
|
|||
package docs.jrouting;
|
||||
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.actor.ActorSystem;
|
||||
|
||||
//#imports1
|
||||
import akka.actor.UntypedActor;
|
||||
import akka.routing.ConsistentHashingRouter.ConsistentHashable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.Serializable;
|
||||
//#imports1
|
||||
|
||||
|
||||
//#imports2
|
||||
import akka.actor.Props;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.routing.ConsistentHashingPool;
|
||||
import akka.routing.ConsistentHashingRouter;
|
||||
import akka.routing.ConsistentHashingRouter.ConsistentHashMapper;
|
||||
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope;
|
||||
|
|
@ -120,7 +125,7 @@ public class ConsistentHashingRouterDocTest {
|
|||
};
|
||||
|
||||
ActorRef cache = system.actorOf(
|
||||
new ConsistentHashingRouter(10).withHashMapper(hashMapper).props(
|
||||
new ConsistentHashingPool(10).withHashMapper(hashMapper).props(
|
||||
Props.create(Cache.class)),
|
||||
"cache");
|
||||
|
||||
|
|
|
|||
|
|
@ -317,12 +317,11 @@ public class RouterDocTest {
|
|||
public void demonstrateDispatcher() {
|
||||
//#dispatchers
|
||||
Props props =
|
||||
// “head” will run on "router-dispatcher" dispatcher
|
||||
new RoundRobinPool(5).withDispatcher("router-dispatcher").props(
|
||||
Props.create(Worker.class))
|
||||
// Worker routees will run on "workers-dispatcher" dispatcher
|
||||
.withDispatcher("workers-dispatcher");
|
||||
ActorRef router = system.actorOf(props);
|
||||
// “head” router actor will run on "router-dispatcher" dispatcher
|
||||
// Worker routees will run on "pool-dispatcher" dispatcher
|
||||
new RandomPool(5).withDispatcher("router-dispatcher").props(
|
||||
Props.create(Worker.class));
|
||||
ActorRef router = system.actorOf(props, "poolWithDispatcher");
|
||||
//#dispatchers
|
||||
}
|
||||
|
||||
|
|
@ -390,8 +389,8 @@ public class RouterDocTest {
|
|||
public void demonstrateRemoteDeploy() {
|
||||
//#remoteRoutees
|
||||
Address[] addresses = {
|
||||
new Address("akka", "remotesys", "otherhost", 1234),
|
||||
AddressFromURIString.parse("akka://othersys@anotherhost:1234")};
|
||||
new Address("akka.tcp", "remotesys", "otherhost", 1234),
|
||||
AddressFromURIString.parse("akka.tcp://othersys@anotherhost:1234")};
|
||||
ActorRef routerRemote = system.actorOf(
|
||||
new RemoteRouterConfig(new RoundRobinPool(5), addresses).props(
|
||||
Props.create(Echo.class)));
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ Once a connection has been established data can be sent to it from any actor in
|
|||
|
||||
Tcp.Write
|
||||
The simplest ``WriteCommand`` implementation which wraps a ``ByteString`` instance and an "ack" event.
|
||||
A ``ByteString`` (as explained in :ref:`this section <ByteString>`) models one or more chunks of immutable
|
||||
A ``ByteString`` (as explained in :ref:`this section <bytestring_java>`) models one or more chunks of immutable
|
||||
in-memory data with a maximum (total) size of 2 GB (2^31 bytes).
|
||||
|
||||
Tcp.WriteFile
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ nacked messages it may need to keep a buffer of pending messages.
|
|||
the I/O driver has successfully processed the write. The Ack/Nack protocol described here is a means of flow control
|
||||
not error handling. In other words, data may still be lost, even if every write is acknowledged.
|
||||
|
||||
.. _ByteString:
|
||||
.. _bytestring_java:
|
||||
|
||||
ByteString
|
||||
^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -627,16 +627,25 @@ The deployment section of the configuration is passed to the constructor.
|
|||
Configuring Dispatchers
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The dispatcher for created children of the router will be taken from
|
||||
``Props`` as described in :ref:`dispatchers-java`. For a pool it
|
||||
The dispatcher for created children of the pool will be taken from
|
||||
``Props`` as described in :ref:`dispatchers-scala`. For a pool it
|
||||
makes sense to configure the ``BalancingDispatcher`` if the precise
|
||||
routing is not so important (i.e. no consistent hashing or round-robin is
|
||||
required); this enables newly created routees to pick up work immediately by
|
||||
stealing it from their siblings.
|
||||
|
||||
To make it easy to define the dispatcher of the routees of the pool you can
|
||||
define the dispatcher inline in the deployment section of the config.
|
||||
|
||||
.. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-pool-dispatcher
|
||||
|
||||
That is the only thing you need to do enable a dedicated dispatcher for a
|
||||
pool.
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
If you provide a collection of actors to route to, then they will still use the same dispatcher
|
||||
If you use a group of actors and route to their paths, then they will still use the same dispatcher
|
||||
that was configured for them in their ``Props``, it is not possible to change an actors dispatcher
|
||||
after it has been created.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue