如何将Erlang Processes映射到内核线程? [英] How, if at all, do Erlang Processes map to Kernel Threads?

查看:199
本文介绍了如何将Erlang Processes映射到内核线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Erlang以能够支持多个轻量级流程而着称;它可以做到这一点,因为这些不是传统意义上的进程,甚至是P线程中的线程,而是在用户空间中完全线程。



这是很好的(真的很棒)。但是如何在多核/多处理器环境中并行执行Erlang线程呢?当然,他们必须以某种方式映射到内核线程,以便在单独的内核上执行?



假设是这样,这是怎么做到的?许多轻量级进程映射到单个内核线程?



还是有另一种方法来解决这个问题?

解决方案

答案取决于使用的虚拟机:



1)非SMP :有一个调度程序(OS线程),它执行所有Erlang进程,取自可运行进程池(即那些未被例如 / code>)



2) SMP :有 K调度程序(OS线程,K是通常是一些CPU内核),它们从共享进程队列执行Erlang进程。它是一个简单的FIFO队列(具有允许从多个OS线程同时访问的锁)。



3)在R13B和更新版本中的SMP:将从多个进程队列执行Erlang进程的 K调度程序(如前所述)。每个调度程序都有自己的队列,因此将会添加从一个调度程序到另一个调度程序的迁移逻辑。此解决方案将通过避免共享进程队列中的过度锁定来提高性能。



有关更多信息,请参阅本文档由Ericsson AB,为爱尔兰用户会议,斯德哥尔摩,2008年11月13日,由肯尼斯·隆迪编写。


Erlang is known for being able to support MANY lightweight processes; it can do this because these are not processes in the traditional sense, or even threads like in P-threads, but threads entirely in user space.

This is well and good (fantastic actually). But how then are Erlang threads executed in parallel in a multicore/multiprocessor environment? Surely they have to somehow be mapped to kernel threads in order to be executed on separate cores?

Assuming that that's the case, how is this done? Are many lightweight processes mapped to a single kernel thread?

Or is there another way around this problem?

解决方案

Answer depends on the VM which is used:

1) non-SMP: There is one scheduler (OS thread), which executes all Erlang processes, taken from the pool of runnable processes (i.e. those who are not blocked by e.g. receive)

2) SMP: There are K schedulers (OS threads, K is usually a number of CPU cores), which executes Erlang processes from the shared process queue. It is a simple FIFO queue (with locks to allow simultaneous access from multiple OS threads).

3) SMP in R13B and newer: There will be K schedulers (as before) which executes Erlang processes from multiple process queues. Each scheduler has it's own queue, so process migration logic from one scheduler to another will be added. This solution will improve performance by avoiding excessive locking in shared process queue.

For more information see this document prepared by Kenneth Lundin, Ericsson AB, for Erlang User Conference, Stockholm, November 13, 2008.

这篇关于如何将Erlang Processes映射到内核线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆