zakgof / actr

Simple, fast and typesafe Java actor model implementation
Apache License 2.0
119 stars 20 forks source link

Performance: thread starvation is highly possible in `ForkJoinPoolScheduler#schedule` #5

Closed SereneAnt closed 5 years ago

SereneAnt commented 5 years ago

When certain single actr or a set of actrs receive messages with a high rate, thread starvation is highly possible. This will happen in the loop (lines 36-44):

            for(;;) {
                Runnable runnable = mailbox.queue.peek();
                if (runnable != null) {
                    ...
                    runnable.run();
                    mailbox.queue.remove();
                } else

When the message rate is high, a certain 'hot' thread wan't 'yield` the execution to others, that can cause a starvation.

In Akka, this is solved with the throughput parameter, that cops the contents of the mailbox into pieces (batches).

zakgof commented 5 years ago

Fixed in actr 0.1.0 - added throughput parameter with a similar meaning