title: Technically, why are processes in Erlang more efficient than OS threads?
body: <h2>Erlang's Characteristics</h2>
  <p>From <a href="https://rads.stackoverflow.com/amzn/click/com/0596518188" rel="nofollow noreferrer" rel="nofollow noreferrer">Erlang Programming</a> (2009):</p>
  <blockquote>
  <p>Erlang concurrency is fast and scalable. Its processes are lightweight in that the Erlang virtual machine does not create an OS thread for every created process. They are created, scheduled, and handled in the VM, independent of underlying operating system. As a result, process creation time is of the order of microseconds and independent of the number of concurrently existing processes. Compare this with Java and C#, where for every process an underlying OS thread is created: you will get some very competitive comparisons, with Erlang greatly outperforming both languages.</p>
  </blockquote>
  <p>From <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.116.1969&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer"> Concurrency oriented programming in Erlang (pdf)</a> <a href="http://www.scribd.com/doc/6505089/Concurrency-Oriented-Programming-in-Erlang-by-Joe-Armstrong" rel="nofollow noreferrer">(slides)</a> (2003):</p>
  <blockquote>
  <p>We observe that the time taken to create an Erlang process is constant 1µs up to 2,500 processes; thereafter it increases to about 3µs for up to 30,000 processes. The performance of Java and C# is shown at the top of the figure. For a small number of processes it takes about 300µs to create a process. Creating more than two thousand processes is impossible.</p>
  <p>We see that for up to 30,000 processes the time to send a message between two Erlang processes is about 0.8µs. For C# it takes about 50µs per message, up to the maximum number of processes (which was about 1800 processes). Java was even worse, for up to 100 process it took about 50µs per message thereafter it increased rapidly to 10ms per message when there were about 1000 Java processes.</p>
  </blockquote>
  <h2>My thoughts</h2>
  <p>I don't fully understand technically why Erlang processes are so much more efficient in spawning new processes and have much smaller memory footprints per process. Both the OS and Erlang VM have to do scheduling, context switches, and keep track of the values in the registers and so on...</p>
  <p>Simply why aren't OS threads implemented in the same way as processes in Erlang? Do they have to support something more? And why do they need a bigger memory footprint? And why do they have slower spawning and communication?</p>
  <p>Technically, why are processes in Erlang more efficient than OS threads when it comes to spawning and communication? And why can't threads in the OS be implemented and managed in the same efficient way? And why do OS threads have a bigger memory footprint, plus slower spawning and communication?</p>
  <h2>More reading</h2>
  <ul>
  <li><a href="https://erlang.org/euc/08/euc_smp.pdf" rel="nofollow noreferrer">Inside the Erlang VM <em>with focus on SMP</em></a> (2008)</li>
  <li><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.1.9502&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">Concurrency in Java and in Erlang (pdf)</a> (2004)</li>
  <li><a href="http://www.sics.se/%7Ejoe/ericsson/du98024.html" rel="nofollow noreferrer">Performance Measurements of Threads in Java and Processes in Erlang</a> (1998)</li>
  </ul>