- 浏览: 981747 次
- 性别:
- 来自: 广州
最新评论
-
qingchuwudi:
有用,非常感谢!
erlang进程的优先级 -
zfjdiamond:
你好 这条命令 在那里输入??
你们有yum 我有LuaRocks -
simsunny22:
这个是在linux下运行的吧,在window下怎么运行escr ...
escript的高级特性 -
mozhenghua:
http://www.erlang.org/doc/apps/ ...
mnesia 分布协调的几个细节 -
fxltsbl:
A new record of 108000 HTTP req ...
Haproxy 1.4-dev2: barrier of 100k HTTP req/s crossed
/* process priorities */
#define PRIORITY_MAX 0
#define PRIORITY_HIGH 1
#define PRIORITY_NORMAL 2
#define PRIORITY_LOW 3
#define NPRIORITY_LEVELS 4
process_flag(priority, Level)
This sets the process priority. Level is an atom. There are currently four priority levels: low, normal, high, and max. The default priority level is normal. NOTE: The max priority level is reserved for internal use in the Erlang runtime system, and should not be used by others.
Internally in each priority level processes are scheduled in a round robin fashion.
Execution of processes on priority normal and priority low will be interleaved. Processes on priority low will be selected for execution less frequently than processes on priority normal.
When there are runnable processes on priority high no processes on priority low, or normal will be selected for execution. Note, however, that this does not mean that no processes on priority low, or normal will be able to run when there are processes on priority high running. On the runtime system with SMP support there might be more processes running in parallel than processes on priority high, i.e., a low, and a high priority process might execute at the same time.
When there are runnable processes on priority max no processes on priority low, normal, or high will be selected for execution. As with the high priority, processes on lower priorities might execute in parallel with processes on priority max.
Scheduling is preemptive. Regardless of priority, a process is preempted when it has consumed more than a certain amount of reductions since the last time it was selected for execution.
NOTE: You should not depend on the scheduling to remain exactly as it is today. Scheduling, at least on the runtime system with SMP support, is very likely to be modified in the future in order to better utilize available processor cores.
There is currently no automatic mechanism for avoiding priority inversion, such as priority inheritance, or priority ceilings. When using priorities you have to take this into account and handle such scenarios by yourself.
Making calls from a high priority process into code that you don't have control over may cause the high priority process to wait for a processes with lower priority, i.e., effectively decreasing the priority of the high priority process during the call. Even if this isn't the case with one version of the code that you don't have under your control, it might be the case in a future version of it. This might, for example, happen if a high priority process triggers code loading, since the code server runs on priority normal.
Other priorities than normal are normally not needed. When other priorities are used, they need to be used with care, especially the high priority must be used with care. A process on high priority should only perform work for short periods of time. Busy looping for long periods of time in a high priority process will most likely cause problems, since there are important servers in OTP running on priority normal.
process_flag(save_calls, N)
When there are runnable processes on priority max no processes on priority low, normal, or high will be selected for execution. As with the high priority, processes on lower priorities might execute in parallel with processes on priority max.
N must be an integer in the interval 0..10000. If N > 0, call saving is made active for the process, which means that information about the N most recent global function calls, BIF calls, sends and receives made by the process are saved in a list, which can be retrieved with process_info(Pid, last_calls). A global function call is one in which the module of the function is explicitly mentioned. Only a fixed amount of information is saved: a tuple {Module, Function, Arity} for function calls, and the mere atoms send, 'receive' and timeout for sends and receives ('receive' when a message is received and timeout when a receive times out). If N = 0, call saving is disabled for the process, which is the default. Whenever the size of the call saving list is set, its contents are reset.
不过要慎重使用优先级,除非必要。
#define PRIORITY_MAX 0
#define PRIORITY_HIGH 1
#define PRIORITY_NORMAL 2
#define PRIORITY_LOW 3
#define NPRIORITY_LEVELS 4
process_flag(priority, Level)
This sets the process priority. Level is an atom. There are currently four priority levels: low, normal, high, and max. The default priority level is normal. NOTE: The max priority level is reserved for internal use in the Erlang runtime system, and should not be used by others.
Internally in each priority level processes are scheduled in a round robin fashion.
Execution of processes on priority normal and priority low will be interleaved. Processes on priority low will be selected for execution less frequently than processes on priority normal.
When there are runnable processes on priority high no processes on priority low, or normal will be selected for execution. Note, however, that this does not mean that no processes on priority low, or normal will be able to run when there are processes on priority high running. On the runtime system with SMP support there might be more processes running in parallel than processes on priority high, i.e., a low, and a high priority process might execute at the same time.
When there are runnable processes on priority max no processes on priority low, normal, or high will be selected for execution. As with the high priority, processes on lower priorities might execute in parallel with processes on priority max.
Scheduling is preemptive. Regardless of priority, a process is preempted when it has consumed more than a certain amount of reductions since the last time it was selected for execution.
NOTE: You should not depend on the scheduling to remain exactly as it is today. Scheduling, at least on the runtime system with SMP support, is very likely to be modified in the future in order to better utilize available processor cores.
There is currently no automatic mechanism for avoiding priority inversion, such as priority inheritance, or priority ceilings. When using priorities you have to take this into account and handle such scenarios by yourself.
Making calls from a high priority process into code that you don't have control over may cause the high priority process to wait for a processes with lower priority, i.e., effectively decreasing the priority of the high priority process during the call. Even if this isn't the case with one version of the code that you don't have under your control, it might be the case in a future version of it. This might, for example, happen if a high priority process triggers code loading, since the code server runs on priority normal.
Other priorities than normal are normally not needed. When other priorities are used, they need to be used with care, especially the high priority must be used with care. A process on high priority should only perform work for short periods of time. Busy looping for long periods of time in a high priority process will most likely cause problems, since there are important servers in OTP running on priority normal.
process_flag(save_calls, N)
When there are runnable processes on priority max no processes on priority low, normal, or high will be selected for execution. As with the high priority, processes on lower priorities might execute in parallel with processes on priority max.
N must be an integer in the interval 0..10000. If N > 0, call saving is made active for the process, which means that information about the N most recent global function calls, BIF calls, sends and receives made by the process are saved in a list, which can be retrieved with process_info(Pid, last_calls). A global function call is one in which the module of the function is explicitly mentioned. Only a fixed amount of information is saved: a tuple {Module, Function, Arity} for function calls, and the mere atoms send, 'receive' and timeout for sends and receives ('receive' when a message is received and timeout when a receive times out). If N = 0, call saving is disabled for the process, which is the default. Whenever the size of the call saving list is set, its contents are reset.
不过要慎重使用优先级,除非必要。
发表评论
-
OTP R14A今天发布了
2010-06-17 14:36 2675以下是这次发布的亮点,没有太大的性能改进, 主要是修理了很多B ... -
R14A实现了EEP31,添加了binary模块
2010-05-21 15:15 3030Erlang的binary数据结构非常强大,而且偏向底层,在作 ... -
如何查看节点的可用句柄数目和已用句柄数
2010-04-08 03:31 4812很多同学在使用erlang的过程中, 碰到了很奇怪的问题, 后 ... -
获取Erlang系统信息的代码片段
2010-04-06 21:49 3473从lib/megaco/src/tcp/megaco_tcp_ ... -
iolist跟list有什么区别?
2010-04-06 20:30 6524看到erlang-china.org上有个 ... -
erlang:send_after和erlang:start_timer的使用解释
2010-04-06 18:31 8384前段时间arksea 同学提出这个问题, 因为文档里面写的很不 ... -
Latest news from the Erlang/OTP team at Ericsson 2010
2010-04-05 19:23 2013参考Talk http://www.erlang-factor ... -
对try 异常 运行的疑问,为什么出现两种结果
2010-04-05 19:22 2837郎咸武<langxianzhe@163.com> ... -
Erlang ERTS Async基础设施
2010-03-19 00:03 2517其实Erts的Async做的很不错的, 相当的完备, 性能又高 ... -
CloudI 0.0.9 Released, A Cloud as an Interface
2010-03-09 22:32 2471基于Erlang的云平台 看了下代码 质量还是不错的 完成了不 ... -
Memory matters - even in Erlang (再次说明了了解内存如何工作的必要性)
2010-03-09 20:26 3438原文地址:http://www.lshift.net/blog ... -
Some simple examples of using Erlang’s XPath implementation
2010-03-08 23:30 2048原文地址 http://www.lshift.net/blog ... -
lcnt 环境搭建
2010-02-26 16:19 2611抄书:otp_doc_html_R13B04/lib/tool ... -
Erlang强大的代码重构工具 tidier
2010-02-25 16:22 2484Jan 29, 2010 We are very happy ... -
[Feb 24 2010] Erlang/OTP R13B04 has been released
2010-02-25 00:31 1385Erlang/OTP R13B04 has been rele ... -
R13B04 Installation
2010-01-28 10:28 1385R13B04后erlang的源码编译为了考虑移植性,就改变了编 ... -
Running tests
2010-01-19 14:51 1483R13B03以后 OTP的模块加入了大量的测试模块,这些模块都 ... -
R13B04在细化Binary heap
2010-01-14 15:11 1506从github otp的更新日志可以清楚的看到otp R13B ... -
R13B03 binary vheap有助减少binary内存压力
2009-11-29 16:07 1665R13B03 binary vheap有助减少binary内存 ... -
erl_nif 扩展erlang的另外一种方法
2009-11-26 01:02 3216我们知道扩展erl有2种方法, driver和port. 这2 ...
相关推荐
- **并发编程**:在多线程或进程环境中,优先级队列可以帮助决定哪个任务应该首先获得处理资源。 **总结** `pqueue` 库为 Erlang 提供了一个强大的优先级队列实现,使得开发者可以方便地在项目中利用优先级队列的...
- **概念**: Port驱动程序允许Erlang进程与外部程序进行通信。 - **实现**: 通过`erlang:open_port/2`函数创建一个Port。 - **应用场景**: 实现Erlang与C语言编写的程序之间的交互。 #### 13. SMP支持 - **概念**: ...
Erlang的并发模型基于轻量级进程,这些进程之间的通信主要通过消息传递来进行。每个进程都有一个独立的消息队列,并且可以通过发送消息给其他进程来启动异步任务或请求服务。这种模型非常适合实现高度并行和容错的...
- Erlang进程的调度机制是如何工作的。 - 实时性是指系统能够及时响应外部事件的能力,而优先级则决定了进程执行的先后顺序。 **5.7 进程组** - 如何将进程组织成组。 - 进程组可以简化管理和监控多个进程的工作。 ...
- **并发性**:Erlang进程模型使得在单个节点上并行运行大量轻量级进程成为可能,这些进程通过消息传递进行通信,减少了竞争条件和同步问题。 - **热代码替换**:Erlang支持在运行时更新和升级代码,无需重启服务,...
`spawn()`函数用于创建新进程,而`process_flag(priority, Priority)`则允许设置进程的优先级,其取值包括`high`、`normal`和`low`。为了监控系统状态,`etop`工具(位于`erlang/lib/observer-xxx/priv/bin`目录下)...
进程标识符是 Erlang 进程间的通信机制之一,用于标识进程的身份。手册中详细介绍了 Pid 的概念、生成方式以及如何通过 Pid 发送消息。 **1.2.9 元组(Tuple)** 元组是由多个有序元素组成的不可变数据结构,常用于...
它通过设置oom_score_adj值来降低Erlang心跳进程的优先级,使得即使在系统内存紧张的情况下,这些关键进程也不会被内核轻易杀死。这样,可以确保Erlang集群的核心服务得以维持,从而提高系统的整体稳定性。 **使用...
在Erlang中实现HTTP/2服务器,可能需要利用其内置的轻量级进程(processes)和消息传递机制,这些特性非常适合并发处理和错误恢复。Erlang的 OTP(Open Telecom Platform)库提供了丰富的工具和设计模式,如...
其设计目标是处理大规模并发连接,具有内置的错误恢复机制和轻量级进程模型,这使得Erlang在分布式计算、实时系统和容错领域表现出色。 OTP(Open Telecom Platform)是一套框架、库和设计原则的集合,旨在简化...
2. **并发执行**:Erlang和Elixir的并发模型基于轻量级进程(processes),gen-batch-server可以同时处理多个任务,每个任务在一个独立的进程中运行,确保任务间的隔离和并发性能。 3. **错误处理**:gen-batch-...
基于进程字典来是实现类变量, parse_transform实现类方法的继承.基于 修改,原项目将不再更新维护。%% 优先级选择节点,从左到右遍历子节点,若子节点的准入条件符合信息则执行该子节点-define(EBT_SELECTOR, ebt_...
3. **消息队列(Message Queue)**:Erlang进程间的通信依赖于消息传递,因此项目可能包含一个消息队列,用于在任务调度器和执行器之间传输任务描述和结果。 4. **错误处理与恢复(Error Handling and Recovery)**...
- **并发性**:Erlang的进程模型使得创建轻量级并发进程非常容易,这为构建高并发、高可用的系统提供了基础。 - **热代码升级**:Erlang支持在不中断服务的情况下更新运行中的代码,这在系统维护和升级时非常有用。 ...
3. **请求处理**:每个书籍请求可能作为一个独立的Erlang进程来处理,这样可以确保请求之间的隔离,并且可以通过消息队列来管理请求的顺序和优先级。 4. **状态管理**:ErlangDatabase可能会使用ETS(Erlang Term ...
Erlang是一种并发性极强的编程语言,OTP(Open Telecom Platform)是其生态系统的一部分,提供了可靠的服务和进程管理框架。Gun在Erlang环境中为开发者提供了高效、稳定且功能丰富的网络通信工具。 Gun支持以下...
3. **分布式程序设计语言**:这些语言允许开发者编写能够跨多个节点执行的程序,例如Erlang、Rust和Go等。它们通常具有内置的并发支持,以及处理分布式故障和容错的能力。 4. **同步互斥**:在多线程或分布式环境中...
- **Erlang OTP**: Erlang的开放电信平台,提供进程管理、分布式计算和错误恢复机制,确保RabbitMQ的高可用性。 ### 7. 使用与集成 - 安装RabbitMQ:在不同操作系统上安装RabbitMQ服务器,配置环境变量和启动服务...