Kernel Poll on ejabberd

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.

你可能感兴趣的:(Kernel Poll on ejabberd)