Setting the number of cores used by the BEAM
Most of the time when we write our BEAM apps, we rely on defaults when it comes to the number of cores used by the system. But sometimes it is useful to be able to control the number cores for debugging purposes. For example, you may want to optimise some costs by checking how much power you need for some task. Or, you want to avoid parallelising some computation where concurrency is what you're actually looking for.
TL; DR; To limit the number of cores, you have to set the +S
flag when starting the Erlang runtime system.
Here's an example for Elixir:
iex --erl '+S 2:1' -S mix
Here we create 2 schedulers but keep only one online, which will be actively used (one core respectively). To see that this is actually true, we can inspect our system with the Observer
tool:
iex(1)> :observer.start
:ok
This will open a window with a lot of information about our system.
Find more options in the official Erlang documentation.
Member discussion