[erlang-questions] How many async threads can be spawned in dual core system ?
Wed May 31 10:21:34 CEST 2017
On 2017年05月31日 水曜日 13:21:29 lankeanandrao wrote:
> I want to know, How many maximum number of async threads can be
> spawned for dual core processor.
As many as the other aspects of your system can handle.
"Other aspects" meaning: memory, your Erlang runtime's settings, etc.
"Threads" are a poor way of thinking about this. Erlang processes are Erlang processes. Generally speaking, that is the level of abstraction you should be concerned with, not "threads" which is a different level of abstraction entirely (by every common definition of "thread").
The Erlang runtime will by default spawn a "scheduler" per thing that appears in your operating system as a "core" (an actual CPU core, or a "hyperthread", a virtualized core, or whatever). These schedulers are OS-level threads and work together to share the work of your Erlang processes among them. Within the Erlang runtime, though, you spawn as many processes as you want, and the schedulers take care of making sure they each get a "fair" amount of execution time among them.
I am generalizing a lot, but basically you don't think about things in terms of "how many cores do I have and how many threads does that let me use..." and so on. That is quite low-level. Erlang abstracts that away -- which is one of the powerful reasons for using it when you are trying to write a low-latency, highly concurrent system that experienced graceful performance degradation under load.
If you are unfamiliar with the "concurrency-oriented programming" paradigm present in Erlang (similr to "the actor model", though different for a number of nit-picky academic reasons) this may be helpful to skim through:
More information about the erlang-questions