Slide 1

Slide 1 text

elixir for a concurrent world

Slide 2

Slide 2 text

concurrency when two or more tasks can start, run, and complete in overlapping time periods.

Slide 3

Slide 3 text

os processes Pros They have separate sections of memory. No side effects: If VIM crashes, Chrome is unaffected. Cons Unfortunately, expensive...

Slide 4

Slide 4 text

os threads Pros Lighter than OS processes They do not block each other They run on separate CPUs, so they are truly parallel Cons Still pretty heavy weight Shared memory

Slide 5

Slide 5 text

green threads Threads that are scheduled by a virtual machine, rather than the OS. Pros They don't take up a lot of memory. Cons Green thread implementations normally cannot assign work to multiple processors. A blocking I/O operation can block all green threads.

Slide 6

Slide 6 text

so how heavy is "heavy"? A POSIX thread has a configurable stack size. On my machine, the default is 8Mb. JVM, .NET, RubyVM, and CPython all use 1Mb by default. Therefore, memory usage will add up quickly.

Slide 7

Slide 7 text

[Erlang] is a concurrent language – by that I mean that threads are part of the programming language, they do not belong to the operating system. That's really what's wrong with programming languages like Java and C++. It's threads aren't in the programming language, threads are something in the operating system – and they inherit all the problems that they have in the operating system. One of the problems is granularity of the memory management system. The memory management in the operating system protects whole pages of memory, so the smallest size that a thread can be is the smallest size of a page. That's actually too big. -- Joe Armstrong

Slide 8

Slide 8 text

goroutines Initial stack size is 2kb (as of 1.4), but then is dynamically allocated goroutines are green threads that are multiplexed as needed onto native threads, so there isn't a 1:1 mapping.

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

erlang processes

Slide 11

Slide 11 text

so... Not an OS process, but still isolated. No side effects. If a process crashes, other processes are not affected. Managed by the VM, rather than the OS. Immutable data structures sidestep shared mutable state. Processes communicate through message passing. Fault-tolerant

Slide 12

Slide 12 text

go on... Lightweight memory footprint. Dynamically allocated stack. All of this applies to Elixir as well. { _ , b i t s } = : e r l a n g . p r o c e s s _ i n f o ( s p a w n ( f n - > n i l e n d ) , : m e m o r y ) b i t s / 8 # 3 4 0 . 0

Slide 13

Slide 13 text

who cares? we are now able to easily push our systems to over 2 million tcp connections! -- WhatsApp (https://blog.whatsapp.com/196/1-million-is-so- 2011)

Slide 14

Slide 14 text

so how do processes talk?

Slide 15

Slide 15 text

Sources: https://www.youtube.com/watch?v=hlmMi0pWzJE http://blog.nindalf.com/how-goroutines-work/ http://www1.erlang.org/doc/efficiency_guide/processes.html https://speakerdeck.com/7grok/processes-threads-and-the- death-of-moores-law http://learnyousomeerlang.com/ https://www.infoq.com/presentations/erlang-software-for-a- concurrent-world