Search code examples
scalaakkaakka-http

Why is my Akka application hanging after 1 to 2 days?


In my Akka HTTP application, I have to initialize my actor system multiple times in some cases. Like in my services I need implicit val of executors and actor systems. So, I have initialized an actor system 4 times like this in my service layer classes:

private implicit val actorSystem = ActorSystem()

I have terminated only one actor system which is at root level. Others not terminated.

Does this impact on my application performance? Because my application is hanging after 1 to 2 days running.


Solution

  • Using many actor systems in your application is a bad idea.

    Basically each ActorSystem comes with a default dispatcher which is backed by a fork-join pool. This pool does a really great job at balancing work and available threads. That is, if you run many actor systems on the same JVM, this will end up creating way too many (virtual) threads, killing the performance in the process. Ideally you want as many threads as you have CPU cores with optimal utilization.

    Please go through this article once https://manuel.bernhardt.io/2016/08/23/akka-anti-patterns-too-many-actor-systems/

    Also please do let me know if this answers your question.