Instance of BEAM, sharing resources

(1) When I run multiple applications on the same machine, does it create single or multiple instances of BEAM?

(2) Does ets belong to a single application or is it shared among all the applications running on a machine? Isolation level-wise.

The issue here is that “application” is a loaded term, having different interpretations in BEAM projects and on the OS level.

If you start, from your OS, your project using mix run, or iex -S mix, or bin/release start, or some other way, it will start one BEAM instance (one OS level process). This project contains many BEAM applications inside it, one being your application, the others being things like :os_mon, :logger, :ssl, and so on, which run in the same instance. If you then start, from the OS, another project or a new OS process of the same project, it will start a different BEAM instance. It’s like Java, if you start two programs from the OS, they will start their own JVM instances.

ETS is local to a BEAM instance. All BEAM applications in that instance access the same ETS, though tables can have specific access rights. If you start another BEAM instance from your OS, it will have its own ETS.

AFAIK the only thing shared between BEAM instances is epmd, which is the Erlang port mapper daemon.

Personally I don’t see use cases for running multiple BEAM instances on the same system, unless you want total isolation for some reason. Rather you would integrate your different BEAM applications into one project (umbrella project perhaps) that can be started as one instance.

2 Likes

And if I started 2 or 3 projects, would there be 2 or 3 instances of BEAM?

It’s like Java, if you start two programs from the OS, they will start their own JVM instances.

1 Like