9 ms·
Node.js and Elixir/Erlang have two different models of concurrent programming. Node has its single threaded event loop and Elixir uses the Actor model. Practica
by perishabledave 11y ago
Node.js and Elixir/Erlang have two different models of concurrent programming. Node has its single threaded event loop and Elixir uses the Actor model. Practically that means that your code is split into many small individual actors or routines that are highly concurrent (and parallelizable) and work together by speaking to each other.
Some specific advantages of Elixir's model of concurrency along with it's implementation is:
* BEAM (Elixir/Erlang's VM) creates a schedulers for each core in your machine. Processes are efficiently loaded across each scheduler. This means that your application can easily make use of and scale with the cores of your computer.
* Processes are lightweight. These processes are much smaller in size than an operating system process or thread. It isn't uncommon for an Elixir application to have hundreds of thousands of these lightweight processes. In a way, an Elixir application is almost like a micro service architecture, each process does a small little thing and communicates with other processes to work together.
* Processes can be preempted. A node block can yield on IO operations, but what if a block is CPU intensive. The other blocks waiting in the queue will starve. In BEAM the scheduler can preempt a process if it's taking to long and let other processes have some time on the CPU.
* Processes can crash and thats ok. Since processes don't share memory, they can crash without corrupting the memory of other processes. Elixir/Erlang also has a great library (OTP) that deals with handling how processes crash. If a process crashes it can be restarted without having to restart your whole application. One of Erlang's flagship applications was quoted to have nine nines uptime. That's 99.9999999% uptime. That's not because it didn't have errors, but because the application knows how to deal with those errors without having to bring the whole application down.
Hope that helps.