How heavy are Java threads compared to Scala / Akka?

I just compared the performance of scala actors against java threads.

I was amazed to see the difference, I noticed that with my system I was able to create a maximum of ~ 2000 threads (only at a time). But with the same system, I was able to create ~ 500,000 scala members,

Both programs use about 81 MB of heap JVM memory.

Can you explain how much java thread is much heavier than scala / akka actors? What is the key factor that made the scala active of this very light weight?

If I want to achieve the best scalability, should I switch to an actor-based web server instead of a traditional application or Java web server like JBoss or Tomcat?

Thank.

+47
java performance multithreading scala akka
Mar 21 '13 at 17:09
source share
2 answers

Scala actors (including Akka) use Java threads. There is no magic: more than a few thousand threads running simultaneously is a problem for most desktop computers.

The Actor model allows actors with proactive actions that do not occupy a thread if they have no work. Some problems can be effectively modeled, as many sleepers are waiting to get some work, who will do it relatively quickly, and then fall asleep again. In this case, actors are a very efficient way to use Java threads to do your work, especially if you have a library like Akka where performance has been a high priority.

Akka docs explain the basics well.

All sufficiently scalable web servers must solve this problem anyway; you probably shouldn't base your decision on a web server primarily on whether actors are used under the hood, and no matter what you use, you can always add actors yourself.

+36
Mar 21 '13 at 17:27
source share

Acc Acc is not equivalent to a thread. This is more like Callable , which runs in threadpool.

When a message is sent to an actor, that actor is placed in threadpool to process the message. When this is done, the combined thread can be used to execute other members.

+15
Mar 21 '13 at 17:26
source share



All Articles