multithreadingerlanglightweight-processes

Erlang - map each "erlang process" to new kernel thread


I am studying an erlang based system, and trying to analyze the sequence of events that take place in the system. Is there a way to force erlang run-time or the elang vm to create a new kernel thread, each time "spawn" is called. This would make the system slower, but it would make the study a lot easier. I have tried the +S flag, and enabled smp already, but I suspect the system is still mapping multiple processes to one kernel thread, or erlang scheduler. Are there any inputs/configuration parameters I am missing?


Solution

  • No, it is not how Erlang VM works. BEAM spawns threads for each core and runs scheduler there. Each Erlang process can run on any scheduler or even migrate from a scheduler to a scheduler which makes them migrate from one thread to another. By default, those schedulers are not even bound to the CPU core so they could migrate from core to core. You can bind them using -sbt switch. You can also bind Erlang process to the specific scheduler which is undocumented and highly not recommended. You can't spawn a thread from Erlang but from NIF or port but then you can't run Erlang process at this thread anyway.