Why akka tell message is much slower than Java TheadPoolExcutor submit?

Our company’s engine is built with akka and we are doing performance stress testing.
We found that akka tell message is very slow,100 message use about 5-6ns.
The result confused us,so we do a test
(1)send 100 message to 100 actors,calculate time
(2)send 100 task to TheadPoolExcutor,calculate time
dispatcher and TheadPoolExcutor are both 32 threads
but the result is different
actors use 5-6ns and TheadPoolExcutor use 0-1ns
Can someone help us see what’s going on in akka?
The test code is here

Are you talking about the time it takes for tell to hand off the message to the mailbox and return vs enqueueing a runnable to a thread pool, not the time it takes to actually schedule and execute the workload?

There isn’t much going on in that execution path, an allocation, some indirection, but probably more than in the thread pool.

The actor model provides quite a deal more than just executing a workload like Runnable - a way to safely interact with mutable state from multiple threads via messages, a lifecycle for the state (actor), and the possibility to do the interaction in the same way for local and distributed actors across multiple machines.

This comes with some small cost compared to just running a set of isolated Runnable instances. Just like scheduling tasks on a thread pool comes with a cost compared to running them directly in the same thread in a while loop.

1 Like