Erlang 和 C/C++螺纹加工
如果我使用 erlang 作为生成器进程,它会执行一些对速度不太关键的主要功能,例如与服务器通信和处理服务器-客户端通信消息。
然后我选择在 erlang 中生成一个进程并从中运行 c/c++ 代码,这会让我的代码更快吗?
erlang 会比 c/c++ 中的等效项更有效地处理多线程吗?
如果我要从 erlang 生成许多 c 节点,它们会堆叠在单个核心上还是 erlang 会处理多线程。这是我想知道的要点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在问题中谈论了两个不同的概念:运行 C/C++ 代码的 Erlang 进程和 C 节点。
从 Erlang 内部运行的 C 或 C++ 代码根本没有被调度。事实上,它会阻塞当前 CPU 核心的 Erlang 调度程序,因此在 C-land 中运行时间较长很可能会扰乱您的 (Erlang) 调度。
例如,在四核处理器上,Erlang 默认情况下会创建 4 个调度程序线程,每个线程占用一个核心。任何运行 C 代码的进程都会阻塞分配给它的调度程序,直到该代码执行完毕。
运行 C 节点时,您完全依靠自己。 Erlang节点根本不知道C节点的调度,它只关心自己的调度。当然,您可以创建自己的调度,例如将一个核心专用于 C 节点,将三个核心专用于 Erlang 节点或类似的东西。
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.
Erlang 仅使用自己的轻量级进程来管理并发,这些进程不基于线程。它通常只运行几个线程,为它可以生成的数千个进程提供服务,当启用 SMP 时,每个 CPU/核心通常只有一个线程。
它绝对不知道任何外部线程的任何信息,任何外部进程只会增加通信开销以及管理外部进程中的内存和资源的复杂性。
Erlang only manages concurrency using its own lightweight processes, which are not thread based. It usually only runs a few threads that service the many thousands of processes it can spawn, which are usually only one thread per CPU/core when SMP is enabled.
It definitely doesn't know anything about any external threads, and any external processes will just add communication overhead and complexity of managing memory and resources in the external process.