Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Such results are caused with the specifics of your benchmark (a lot of small messages that fill the actor's mailbox quicker than it can handle them). </p> <p>Generally, <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src//actors/scala/actors/Reactor.scala#L201" rel="nofollow">the workflow of <code>react</code></a> is following: </p> <ol> <li>Actor scans the mailbox;</li> <li>If it finds a message, it <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src//actors/scala/actors/Reactor.scala#L131" rel="nofollow">schedules the execution</a>;</li> <li>When the scheduling completes, or, when there're no messages in the mailbox, actor suspends (<code>Actor.suspendException</code> is thrown);</li> </ol> <p>In the first case, when the handler finishes to process the message, execution proceeds straight to <code>react</code> method, and, as long as there're lots of messages in the mailbox, actor immediately schedules the next message to execute, and only after that suspends.</p> <p>In the second case, <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src//actors/scala/actors/Combinators.scala#L26" rel="nofollow"><code>loop</code></a> <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src//actors/scala/actors/Reactor.scala#L269" rel="nofollow">schedules the execution of <code>react</code></a> in order to prevent a stack overflow (which might be your case with Actor #1, because tail recursion in <code>process</code> is not optimized), and thus, execution doesn't proceed to <code>react</code> immediately, as in the first case. That's where the millis are lost. </p> <hr> <p><b>UPDATE</b> (taken from <a href="http://erikengbrecht.blogspot.com/2010/08/scala-actors-loop-react-and-schedulers.html" rel="nofollow">here</a>):</p> <blockquote> <p>Using loop instead of recursive react effectively doubles the number of tasks that the thread pool has to execute in order to accomplish the same amount of work, which in turn makes it so any overhead in the scheduler is far more pronounced when using loop.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload