I. Summary
Dispatchers is the heart of the Akka application and this is what makes it
Humming. Routers on the other hand, route incoming messages to outbound actors II, Dispatcher type
Dispatcher
Features are as follows:
Every actor is backed by its own mailbox
the dispatcher can is shared with any number of actors
the dispatcher can be backed by either thread pool or fork join pool
the dispatcher is optimized for non-blocking code
Pinned Dispatcher
Characteristics
Every actor is backed by its own mailbox.
a dedicated thread for each actor implies the This dispatcher cannot be
Shared with any other actors.
the dispatcher is backed by the thread pool executor.
the dispatcher is optimized for blocking operations. For example, if the code
is making I/O calls or database calls, then such actors would wait until the task
is finished. For such blocking operation, the pinned Dispatcherperforms
Better than the default dispatcher
Balancing Dispatcher
Characteristics:
There is only one mailbox for all actors
the dispatcher can is shared only with actors of the same type
the dispatcher can be backed by a either thread pool or fork join pool
Calling thread Dispatcher
Characteristics:
Every actor is backed by its own mailbox
the dispatcher can is shared with any number of actors
the dispatcher is backed by the calling thread III, mailboxes type
blocking queue:blocking queue means a queue that waits for space to
Become available before putting in a element and similarly waits for t
Queue to become non-empty before retrieving an element
bounded queue:bounded queue means a queue that limits the size of
Queue Meaning cannot add more elements than the specified size four Thread pool executor with Fork join executor
thread pool Executor:here, the idea was to create a pool of worker threads.
Tasks is assigned to the pool using a queue. If the number of the tasks exceeds
The number of threads, then the tasks is queued up until a thread in the
Pool is available. Worker threads minimize the overhead of allocation/
Deallocation of Threads.
Fork Join Executor:this is based on the premise of Divide-and-conquer. The
Idea was to divide a large task in smaller tasks whose solution can then be
Combined for the final answer. The tasks need to being independentto be able
Run in parallel.
Calculation rules:
minimum number of threads that'll be allocated
maximum number of threads that'll be allocated
multiplier factor to being used (based on number of CPU cores available)
For example, if the minimum number was defined as 3 and the multiplier factor is
2, then the dispatcher starts with a minimum of 3 x 2 = 6 threads. The maximum
Number defines the upper limit on the number of threads. If the maximum number is
8, then the maximum number of threads would be 8 x 2 = Threads
Thread Pool Executor Configuration method:
# Configuration for the thread pool
thread-pool-executor {
# Minimum number of threads
core-pool-size-min = 2< c3/># Available processors * factor
Core-pool-size-factor = 2.0
# Maximum number of threads
Core-pool-size-max = Ten
}
Fork Join Executor Configuration method
# Configuration for the fork join pool
fork-join-executor {
# Min number of threads
parallelism-min = 2
# Available Processors * Factor
Parallelism-factor = 2.0
# Max number of threads
Parallelism-max = Ten
}
Complete one dispatch configuration
My-dispatcher {
type = Dispatcher
executor = "Fork-join-executor"
fork-join-executor {
Parallelism-min = 2
parallelism-factor = 2.0
Parallelism-max = Ten
}
throughput =
mailbox-capacity =-1
mailbox-type = ""
}
Code implementation
Actorsystem _system = actorsystem.create ("Dispatcher",
configfactory.load (). GetConfig ("Mydispatcherexample") );
Actorref actor = _system.actorof (new Props (Msgechoactor.class)
. Withdispatcher ("My-dispatcher"));
Wu, Routers