关于Erlang Socket的三种消息接收模式
来源:互联网 发布:windows连不上sens 编辑:程序博客网 时间:2024/06/09 04:58
转载请注明,来自:http://blog.csdn.net/skyman_2001
erlang的socket有3种消息接收模式:active、passive和active once,可以在gen_tcp:connect/3或gen_tcp:listen/2里设置{active, true | false |once}来实现,也可以用inet:setopts/2来动态设置。这3种模式的区别是:
1. active(主动消息接收):非阻塞。当数据到达时系统会向控制进程发送{tcp, Socket, Data}消息。控制进程无法控制消息流;
2. passive(被动消息接收):阻塞。控制进程必须主动调用recv()来接收消息。可以控制消息流;
3. active once(混合消息接收):半阻塞。这种模式是主动的但仅针对一个消息,在控制进程收到一个消息后,必须显式调用inet:setopts(Socket, [{active, once}])来重新
激活以接收下一个消息。可以进行流量控制。这种模式相对于被动模式来说,有个优点是可以同时等待多个socket的数据。
Erlang官方推荐使用active once模式:
Active, once is the recommended way to implement a server in both UDP and
TCP.
The use of active once is superior to the other alternatives from a
programmatical standpoint, it is clean and robust. I don't recommend the
use of active true or active false just for performance reasons, because it
will cause other problems instead.
We are currently working with improvements regarding active once for TCP
since it obviously seems to be slower than necessary. Most probably it is
the same with UDP and we will look into that as well.
We don't think there need any significant performance difference between
active once and the other alternatives and hope to have a solution
confirming that soon (meaning r15b02 or 03)
Regards Kenneth Erlang/OTP, Ericsson
详见:http://erlang.org/pipermail/erlang-questions/2012-April/065991.html
R15B02对active once进行了优化,降低延迟,最大吞吐量提高4~6倍。详见:https://github.com/erlang/otp/commit/689ba6e5657867eb3efbcb9a2dbec4aa98ddac5d
- 关于Erlang Socket的三种消息接收模式
- Erlang 三种Socket模式
- erlang之三种socket消息循环
- erlang三种socket消息循环
- erlang的消息发送和接收
- 关于erlang socket被动模式和delay_send合用的问题
- 关于erlang socket被动模式和delay_send合用的问题
- 使用socket接收服务器推送的消息
- TCP/IP (三) TCP消息的接收
- 探讨erlang消息选择性接收特性
- 关于WM_NOTIFY消息接收窗口的问题
- 关于ActiveMQ消息接收的问题
- 关于dll中接收消息的问题
- SOS-关于Socket类接收的问题
- 关于异步socket接收数据的困惑
- 关于socket的接收堵塞问题
- 关于socket的接收堵塞问题
- 关于socket的接收堵塞问题
- isnull sql
- Oracle 数据库 Record is locked by another user 问题解决办法
- FilenameFilter 文件过滤器的用法
- HDU1198--Farm Irrigation
- 外包网
- 关于Erlang Socket的三种消息接收模式
- Oracle安全 - SCN的可能最大值与耗尽问题
- jquery and js
- sqlserver grant 语句
- 指针函数与函数指针的区别
- HDU 2527 Safe Or Unsafe (哈夫曼树)
- Linux重启命令init 6和reboot的区别
- 最简单的CI框架入门示例--数据库取数据
- 原地归并排序