Learn the dispatcher of Akka

Source: Internet
Author: User
Tags min
Dispatcher parsing

Dispathcer is responsible for scheduling parallel tasks, assigning work to actors, and assigning resources to handle future callbacks, which can be understood as dispatcher and executor as threads in thread pool scheduler.
Like the thread pool, the default dispathcer is used when you do not create your own dispatcher, and it is easy to fill the default thread pool when there are some time-consuming tasks in the task, which affects the scheduling of other tasks. Excutor

Dispatcher based on Excutor, introduced dispatcher before the introduction of the following Excutor Excutor is divided into two: Forkjoinpool, ThreadPool ThreadPool excutor: There is a Task Force column, The queue contains the work assigned to each queue, the thread is free to claim work from the queue, allowing thread reuse, reducing the overhead of thread allocation and destruction Forkjoinpool Excutor: Use a split algorithm to recursively separate tasks into smaller subtasks, Then the task is assigned to different threads to run, and finally the results are combined forkjoinpoll is almost always more efficient than threadpool, we choose the Dispatcher classification by default Dispatcher: The default dispatcher type, which uses the defined excutor to process messages in the actor, often provides the best performance pinneddispatcher: Assigning a unique thread to each actor, and creating a threadpool for each actor Excutor, each excutor contains a thread that can handle many important tasks in a single actor using this dispatcher, otherwise it is not recommended to use Callingthreaddispatcher: Do not create excutor, Perform work on the thread that initiates the call, primarily for testing or debugging Balancingdispatcher:pool all ACOTR share the same mailbox, and create a county seat for each actor in the pool, It is not recommended to use this class of dispatcher, as long as there are ACOTR in an idle state from the shared mailbox, and the Balancingpool Router dispatcher used in the previous Router section should be used

Above is the theoretical part of Dispather, and the following will focus on how dispatcher is used. Create dispatcher define a dispatcher in the application.conf file, as shown in the parameter resolution Type:dispatcher type, select the dispatcher that matches the scene, Here is the default type Dispatcher executor: Defines the Excutor type, which also describes the two excutor parallelism-min: The minimum number of single cores, the minimum number of threads in Excutor =parallelism-min* Parallelism-factor

# The parallelism factor is used to determine thread pool size using the
# following Formula:ceil (available processor S * factor). Resulting size # is then bounded by the
parallelism-min and Parallelism-max values.
Parallelism-factor = 0.5
This factor is determining the size of the thread pool,
Processors * factor
The thread pool size boundary is set by Parallelism-max parallelism-min Parallelism-factor: This item is best configured as the number of CPU cores of the machine (where the error may be the original author error) Parallelism-max: Maximum number of single core threads , Excutor =parallelism-max*parallelism-factor Throughput: The maximum number of messages per actor before jumping to another ACOTR, this parameter in order to prevent a single acotr from occupying threads, Set the maximum number of messages that this ACOTR will be scheduled to execute
Detect-dispatcher {
  # Dispatcher is the name of the event-based dispatcher
  type = Dispatcher
  # What kind of Ex Ecutionservice to use
  executor = ' fork-join-executor '
  # Configuration for the fork join Pool
  fork-join-executor {
    # Min number of threads to cap factor-based parallelism number to
    parallelism-min = 2
    # P  Arallelism (Threads) ... ceil (available processors * factor)
    parallelism-factor = 24.0
    # Max number of threads to  Cap factor-based parallelism number to
    Parallelism-max = $
  throughput defines the maximum number of Messages to is
  # processed per actor before the thread jumps to the next actor.
  # Set to 1 for as fair as possible.
  Throughput = +
}
Using a custom dispatcher, this creates a detectrouteractor that is defined by your own dispatcher.
Actorsystem Actorsystem = actorsystem.create ("Detecttask");
Actorref routeractorref = actorsystem.actorof (
      props.create (detectrouteractor.class). WithDispatcher (" Detect-dispatcher ");
If you want to use dispatcher based on router and designated mailbox, as long as this creation is good
Actorsystem Actorsystem = actorsystem.create ("Detecttask");
  Actorref routeractorref = actorsystem.actorof (
      props.create (detectrouteractor.class). WithMailbox (" Akka.actor.routermailbox ")
          . Withdispatcher (" Detect-dispatcher "). Withrouter (New Smallestmailboxpool (15000)),
      "Detectrouteractor");
Previous study Akka router next study Akka e-mail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.