`
mryufeng
  • 浏览: 968468 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

erlang进程的优先级

阅读更多
/* 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.

不过要慎重使用优先级,除非必要。
分享到:
评论
1 楼 qingchuwudi 2015-07-31  
有用,非常感谢!

相关推荐

    Erlang进程模型学习PPT

    Erlang进程模型特点 一个进程可以创建数以万计的轻量级进程 每个轻量级进程仅仅完成单一功能 一个复杂的功能可以由多个轻量级进程协同完成 当遇到file或socket等阻塞的io时, 调用的轻量级进程被阻塞,整个进程不...

    Erlang进程池WorkerPool.zip

    Worker Pool 是一个Erlang进程池,其中的工作进程是Erlang的gen server模式进程。Worker Pool的目标是非常简单: 提供以透明的方式管理一批工作进程并且对分配到池中的任务尽最大努力实现负载均衡。一个 Echo 服务器...

    pqueue:Erlang优先级队列

    pqueue:Erlang优先级队列

    erlang 中进程

    关于erlang并发开发的一些例子,便于学习supersivor

    introducing erlang

    ● 并发性 - Erlang支持超大量级的并发进程,并且不需要操作系统具有并发机制。 ● 分布式 - 一个分布式Erlang系统是多个Erlang节点组成的网络(通常每个处理器被作为一个节点) ● 健壮性 - Erlang具有多种基本的...

    erlpool:基于ETS的Erlang进程的Erlang循环负载均衡器

    基于ETS的Erlang进程的Erlang循环负载均衡器 erlpool做什么 Erlpool是用于Erlang进程的循环负载均衡器,主要用于与数据库连接之类的事情。 与和相比, erlpool非常简单且很小(〜100 LOC),并且没有关于工人的假设...

    erlang-18.3.4.7-1.el6.x86_64.rpm

    ●外部接口-Erlang进程与外部世界之间的通讯使用和在Erlang进程之间相同的消息传送机制。 ●Fail-fast(中文译为速错),即尽可能快的暴露程序中的错误。 ●面向并发的编程(COP concurrency-oriented programming) ...

    evum:["Linux VM", ["Erlang 进程", ["Erlang VM"]]]

    在 Erlang VM 中将 Linux VM 作为 Erlang 进程生成。 evum 使 Linux 虚拟机成为 Erlang actor。 虽然 Linux VM 像任何其他进程(内存、系统进程、磁盘)一样拥有自己的状态,但与外部世界的所有 I/O 都是通过 ...

    varpool:Erlang进程池作为局部变量

    varpool:Erlang进程池作为局部变量

    Erlang安装手册

     ●外部接口-Erlang进程与外部世界之间的通讯使用和在Erlang进程之间相同的消息传送机制。  ●Fail-fast(中文译为速错),即尽可能快的暴露程序中的错误。  ●面向并发的编程(COP concurrency-oriented ...

    Erlang并发编程,Erlang程序设计,Erlang中文手册

    使用Erlang编写出的应用运行时通常由成千上万个轻量级进程组成,并通过消息传递相互通讯。进程间上下文切换对于Erlang来说仅仅 只是一两个环节,比起C程序的线程切换要高效得多得多了。 使用Erlang来编写分布式应用...

    erlang编程 Introducing Erlang

    erlang入门电子书 erlang编程 Introducing Erlang,作者Simon.St.Laurent

    erlang_版本24.3.4.4

    erlang 安装包

    ErlangB和ErlangC计算工具(exe可执行文件+excel两个)

    ErlangB和ErlangC计算工具(exe可执行文件+excel两个) ErlangB和ErlangC计算工具(exe可执行文件+excel两个)

    gproc, Erlang的扩展进程注册表.zip

    gproc, Erlang的扩展进程注册表 gproc应用程序作者: 超级用户,约瑟夫 Wayne 。扩展进程字典 注释Gproc有两个依赖项:gen_leader 和 edown 。 由于大多数人都不积极使用,所以默认情况下它们不再被获取。要启用 gen...

    Erlang及其应用Erlang及其应用

    Erlang及其应用Erlang及其应用Erlang及其应用

    erlang otp25 win安装包

    erlang otp25 win安装包

    erlang25.0 windows版本

    erlang25.0 windows版本

    erlang22最新下载包

    erlang22最新下载包 erlang22.1.tar.gz erlang22最新下载包 erlang22最新下载包

    Erlang入门:构建application练习4(进程link的作用)

    Erlang入门:构建application练习4(进程link的作用),实例演示进程link的作用及效果

Global site tag (gtag.js) - Google Analytics