concept BEAM in category elixir

appears as: BEAM, BEAM
Elixir in Action

This is an excerpt from Manning's book Elixir in Action.

Source code written in Erlang is compiled into bytecode that’s then executed in the BEAM. This is where the true magic happens. The virtual machine parallelizes your concurrent Erlang programs and takes care of process isolation, distribution, and the overall responsiveness of the system.

If you address these challenges, your systems can constantly provide service with minimal downtime and failures. Concurrency plays an important role in achieving high availability. In BEAM, the unit of concurrency is a process: a basic building block that makes it possible to build scalable, fault-tolerant, distributed systems.

In BEAM, a process is a concurrent thread of execution. Two processes run concurrently and may therefore run in parallel, assuming at least two CPU cores are available. Unlike OS processes or threads, BEAM processes are lightweight concurrent entities handled by the VM, which uses its own scheduler to manage their concurrent execution.

Figure 5.1 BEAM as a single OS process, using a few threads to schedule a large number of processes

scheduler.tif

By default, BEAM uses as many schedulers as there are CPU cores available. For example, on a quad-core machine, four schedulers are used, as shown in figure 5.1.

Elixir in Action

This is an excerpt from Manning's book Elixir in Action.

Erlang is by no means the fastest platform out there. If you look at various synthetic benchmarks on the Internet, you usually won’t see Erlang high on the list. Erlang programs are run in BEAM and therefore can’t achieve the speed of machine-compiled languages, such as C and C++. But this isn’t accidental or poor engineering on behalf of the Erlang/OTP team.

The goal of the platform isn’t to squeeze out as many requests per seconds as possible, but to keep performance predictable and within limits. The level of performance your Erlang system achieves on a given machine shouldn’t degrade significantly, meaning there shouldn’t be unexpected system hiccups due to, for example, the garbage collector kicking in. Furthermore, as explained earlier, long-running BEAM processes don’t block or significantly impact the rest of the system. Finally, as the load increases, BEAM can use as many hardware resources as possible. If the hardware capacity isn’t enough, you can expect graceful system degradation—requests will take longer to process, but the system won’t be paralyzed. This is due to the preemptive nature of the BEAM scheduler, which performs frequent context switches that keep the system ticking and favors short-running processes. And of course, you can address higher system demand by adding more hardware.

This chapter concludes our basic tour of the language. There is much more to Elixir than we’ve covered so far, but the rest of the book focuses more on BEAM. You’ll learn how to harness its power using Elixir as the programming interface, and we’ll explain additional language features when the need arises.