5 Concurrency primitives

 

This chapter covers

  • Understanding BEAM concurrency principles
  • Working with processes
  • Working with stateful server processes
  • Run-time considerations

Now that you have sufficient knowledge of Elixir and functional programming idioms, we’ll turn our attention to BEAM concurrency—a feature that plays a central role in Elixir’s and Erlang’s support for scalability, fault tolerance, and distribution. In this chapter, we’ll start our tour of BEAM concurrency by looking at basic techniques and tools. Before we explore the lower-level details, we’ll take a look at higher-level principles.

5.1 Concurrency in BEAM

Erlang is all about writing highly available systems—systems that run forever and are always able to meaningfully respond to client requests. To make your system highly available, you must tackle the following challenges:

  • Fault tolerance—Minimize, isolate, and recover from the effects of run-time errors.
  • Scalability—Handle a load increase by adding more hardware resources without changing or redeploying the code.
  • Distribution—Run your system on multiple machines so that others can take over if one machine crashes.

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.

5.2 Working with processes

5.2.1 Creating processes

5.2.2 Message passing

5.3 Stateful server processes

5.3.1 Server processes

5.3.2 Keeping a process state

5.3.3 Mutable state

5.3.4 Complex states

5.3.5 Registered processes

sitemap