Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang and C/C++ Threading

If I use erlang as say a spawner process, it does major functions things that are not too speed critical like communicating with a server and handling server-client communication messages.

Then I choose to spawn a process in erlang and run c/c++ code from it, will this make my code faster?

Will erlang more efficiently handle multithreading than an equivalent in c/c++?

If I were to spawn many c nodes from erlang, would they stack on a single core or would erlang handle the multithreading. This is the main point I am wondering about.

like image 513
BAR Avatar asked Feb 04 '26 13:02

BAR


1 Answers

You talk about two different concepts in your question: Erlang processes running C/C++ code and C nodes.

C or C++ code run from inside Erlang is not scheduled at all. In fact, it will block the Erlang scheduler for the current CPU core, so having long run times in C-land will most likely mess up your (Erlang) scheduling.

For example, on a quad core processor Erlang will by default create 4 scheduler threads, each which will occupy one core. Any process running C code will block the scheduler it is assigned to until that code has finished executing.

When running C nodes, you're totally on your own. An Erlang node does not know about the scheduling of a C node at all, it only cares about it's own scheduling. Of course, you could create your own scheduling such as dedicating one core to the C node and three to the Erlang node or something similar.

like image 102
Adam Lindberg Avatar answered Feb 06 '26 03:02

Adam Lindberg