<div class="gmail_quote">On Mon, Apr 18, 2011 at 9:13 AM, Mike Meyer <span dir="ltr">&lt;<a href="mailto:mwm@mired.org">mwm@mired.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

I always looked at it the other way &#39;round: threading is a hack to<br>
deal with system inadequacies like poor shared memory performance or<br>
an inability to get events from critical file types.<br>
<br>
Real processes and event-driven programming provide a more robust,<br>
understandable and scalable solutions.<br>
&lt;end rant&gt;<br></blockquote></div><br>We need to keep two things separate: threads as a way to achieve concurrency and as a way to achieve parallelism [1].<br><br>It&#39;s useful to use non-determinism (i.e. concurrency) to model a server processing multiple requests. Since requests are independent and shouldn&#39;t impact each other we&#39;d like to model them as such. This implies some level of concurrency (whether using threads and processes).<br>

<br>Now, naively mapping this (concurrent) *programming model* to an *execution model* i.e. OS threads might give us less than optimal performance. At this point what often happens (i.e. in NodeJS and other event driven web frameworks) is that the programming model is thrown out with the execution model. This results in callback-spaghetti and lack of separation of concerns [2].<br>

<br>We don&#39;t need to do this. We can keep a concurrent programming model and get the execution efficiency of an event driven model. This is what GHC&#39;s I/O manager achieves. On top of that we also get parallelism for free. Another way to look at it is that GHC provides the scheduler (using a thread for the event loop and a separate worker pool) that you end up writing manually in event driven frameworks.<br>

<br>-- Johan<br><br>1. <a href="http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/">http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/</a><br>2. <a href="http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf">http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf</a> - This discusses the observer pattern, which is very closely related to how event driven frameworks work (i.e. using callbacks).<br>