Do I need to re-use the same Akka ActorSystem or can I just create one every time I need one?

前端 未结 2 1593
春和景丽
春和景丽 2021-01-30 06:19

Akka 2.x requires many commands to reference an ActorSystem. So, to create an instance of an actor MyActor you might say:



        
2条回答
  •  青春惊慌失措
    2021-01-30 06:50

    Here are some materials which might be helpful to understand "Why does document always suggest to use one ActorSystem for one logical application" :

    1. The heaviest part of an ActorSystem is the dispatcher. Each ActorSystem has at least one. The dispatcher is the engine that makes the actors running. In order to make running, it needs threads (usually got from a thread pool). The default dispatcher uses a fork-join thread pool with at least 8 threads.

    2. There are shared facilities, like the guardian actors, the event stream, the scheduler, etc. Some of them are in user space, some are internal. All of them need to be created and started.

    3. One ActorSystem with one thread pool configures to the numbers of cores should give the best results in most cases.

    4. Here document mentions logical application, I prefer to consider blocking or non-blocking application. According to dispatcher's configuration, one ActorSystem is for one configuration. If the application is for the same logics, one ActorSystem should be enough.

    Here is a discussion , if you have time, you can read it. They discuss a lot, ActorSystem, local or remote, etc.

提交回复
热议问题