Erlang 打开和关闭SMP选项之差异观察

本文探讨了在Erlang otp_19.1版本中开启和关闭SMP(Symmetric MultiProcessing)选项对系统性能的差异。通过实验观察,分析SMP在并发处理、内存使用和响应时间等方面的表现变化。
摘要由CSDN通过智能技术生成

##以下观察是基于版本otp_19.1


#观察SMP enabled

Step 1. 启动erl with SMP enabled (erl -smp enable)

sexxx484: ~/erlang/test  > erl 
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]


Eshell V8.1  (abort with ^G)
1>

#[smp:8:8] 表示在8核的机器上启动了8个scheduler, 每个core对应一个scheduler, 每一个scheduler对应于独立的一个操作系统线程. 启动erlang的时候可以通过选项 +S来设置启动多少个scheduler, 也可以在运行时通过erlang:system_flag 来调整.

+S Schedulers:SchedulerOnline
       Sets the amount of scheduler threads to create and scheduler threads to set online when SMP support has been enabled. Valid range for both values are 1-1024. If the Erlang runtime system is able to determine the amount of logical processors configured and logical processors available, Schedulers will default to logical processors configured, and SchedulersOnline will default to logical processors available; otherwise, the default values will be 1. Schedulers may be omitted if :SchedulerOnline is not and vice versa. The amount of schedulers online can be changed at run time via erlang:system_flag(schedulers_online, SchedulersOnline).
 

Note: the results are similar whether symmetric multiprocessing is enabled or not. To prove it, you can just test it out by starting the Erlang VM with $ erl -smp disable.

To see if your Erlang VM runs with or without SMP support in the first place, start a new VM without any options and look for the first line output. If you can spot the text [smp:2:2] [rq:2], it means you're running with SMP enabled, and that you have 2 run queues (rq, or schedulers) running on two cores. If you only see [rq:1], it means you're running with SMP disabled.

If you wanted to know, [smp:2:2] means there are two cores available, with two schedulers. [rq:2] means there are two run queues active. In earlier versions of Erlang, you could have multiple schedulers, but with only one shared run queue. Since R13B, there is one run queue per scheduler by default; this allows for better parallelism.


 #[async-threads:10] 表示启动了异步线程池, 含有10个异步IO线程.  启动erlang的时候可以通过选项+A来设置启动多少个异步IO线程.

既然说到async thread pool, 这里就解释一下,这个异步线程池的作用. 当你有大量的文件IO操作的时候,这个异步线程池可以改善系统的响应效率,因为这些相对比较耗时的IO操作都放到异步线程池里面来完成了,不会影响到正常的scheduler调度.


下面一段话引用自stackoverflow.


The BEAM runs Erlang code in special threads it calls schedulers. By default it will start a scheduler for every core in your processor. This can be controlled and start up time, for instance if you don't want to run Erlang on all cores but "reserve" some for other things. Normally when you do a file I/O operation then it is run in a scheduler and as file I/O operations are relatively slow they will block that scheduler while they are running. Which can affect the real-time properties. Normally you don't do that much file I/O so it is not a problem.


The asynchronous thread pool are OS threads which are used for I/O operations. Normally the pool is empty but if you use the +A at startup time then the BEAM will create extra threads for this pool. These threads will then only be used for file I/O operations which means that the scheduler threads will no longer block w

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值