1

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?

mac93
  • 197
  • 1
  • 8
  • "Processes" in Erlang are spawned with roughly the same regularity as objects are instantiated in sequential OOP languages. Not a perfect parallel, but its better to think of them like that. [I wrote a thing about this a while back here on SO](http://stackoverflow.com/questions/32294367/erlang-process-vs-java-thread). The difference in paradigms requires leaving a lot of normal programming lore and knowledge behind. – zxq9 Nov 26 '16 at 11:06

1 Answers1

5

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.

Hynek -Pichi- Vychodil
  • 26,174
  • 5
  • 52
  • 73
  • So, does Erlang not allow kernel threads to be dynamically created? Are they created only when the run-time gets started? So if I pass an argument of +S 100:100, it will create 100 kernel threads for the scheduler, and all user threads are shuffled across these 100 kernel threads by Erlang scheduler logic? – mac93 Nov 20 '16 at 22:31
  • @mac93 Yes, they are created when VM starts. There are not user threads, there are Erlang processes which are shuffled across schedulers which all have its own kernel thread. There are also IO threads used solely for IO operations (and IO bound dirty NIFs) and there are experimental dirty threads which are used for CPU bound dirty NIFs. – Hynek -Pichi- Vychodil Nov 20 '16 at 22:49