Kernel Poll on ejabberd

本文介绍如何在Erlang/OTP中启用内核轮询(Kernel Poll)功能来减少CPU使用率,特别是在处理大量并发网络连接时。文章详细说明了启动Erlang节点时如何设置参数以启用该功能,并提供了在ejabberd即时通讯服务器上配置的具体步骤。通过实验对比了启用前后ejabberd的性能变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Support in Erlang/OTP

Several implementations of Kernel Poll are supported since Erlang/OTP R11B-3:

  • FreeBSD (kqueue)
  • Linux 2.4 (/dev/kpoll)
  • Linux 2.6 (/dev/epoll)
  • Solaris (/dev/poll)

How to enable Kernel Poll on an Erlang/OTP node

When starting an Erlang node, by default Kernel Poll is disabled:

$ erl
Erlang R13B04 (erts-5.7.5) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.5 (abort with ^G)
1> q().
ok

To start an Erlang node with Kernel Poll support, you have to provide this argument:

$ erl +K true
Erlang R13B04 (erts-5.7.5) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:true]

Eshell V5.7.5 (abort with ^G)
1> q().
ok

If Erlang or your system does not support Kernel Poll, this would report an error.

Check the performance tuning page for more details.

How to enable Kernel Poll on ejabberd

ejabberd starts Erlang with Kernel Poll enabled by default: the script ejabberdctl starts the Erlang node with the argument mentioned previously. You can disable this by editing the file ejabberdctl.cfg and setting this line:

POLL=false

To know if your configuration will work as you expect, you can start ejabberd in Live mode. This way it will show at the beginning whether Kernel Poll is being used or not. This is the result with the default configuration:

$ ejabberdctl live                                                                                        
--------------------------------------------------------------------

IMPORTANT: ejabberd is going to start in LIVE (interactive) mode.
All log messages will be shown in the command shell.
You can interact with the ejabberd node if you know how to use it.
Please be extremely cautious with your actions,
and exit immediately if you are not completely sure.

To exit this LIVE mode and stop ejabberd, press:
q(). and press the Enter key

--------------------------------------------------------------------
To bypass permanently this warning, add to ejabberdctl.cfg the line:
EJABBERD_BYPASS_WARNINGS=true
Press any key to continue

Erlang R13B04 (erts-5.7.5) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:true]

Eshell V5.7.5 (abort with ^G)
(ejabberd@localhost)1>
=PROGRESS REPORT==== 15-Mar-2010::20:44:15 ===
supervisor: {local,sasl_safe_sup}
started: [{pid,<0.52.0>},
{name,alarm_handler},
{mfa,{alarm_handler,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]
...

How much does it improve performance?

Kernel poll reduces ejabberd's CPU usage when it has hundreds (or more) network connections.
It does not affect memory consumption or latency, so if you plan to support great amounts of simultaneous connected users, you really want to have a Jabber server with Kernel Poll support.

An experiment was ran to compare ejabberd performance with and without Kernel Poll support.
The environment, tools, process and results are available on the Benchmark page, Test 3 .

The next screenshot was taken during the experiment. It shows the ejabberd debug window, Jabsimul window and top. There are 3000 concurrent online users chatting and making roster changes. After 47 minutes of constant stress the ejabberd system process (beam) takes around 5% of CPU usage and nearly 200 megs of RAM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值