About
I read about IQ descipline to understand IQ handler
An IQ discipline defines how an IQ handler (a function) will be executed. There are the following disciplines: - no_queue: all IQs matching the handler are executed sequentially inside the calling process. This is a fast method to execute a handler, however, the drawback is that it blocks the caller. - one_queue: a process is created for the handler and all matching IQs are relayed to this process. The drawback is that the created process' message queue can be overloaded if it doesn't process incoming IQs fast enough, which, in the worst case may crash emulator due to OOM (out-of-memory). - N :: integer(): N parallel processes are created for the handler and all matching IQs are relayed to one of these processes. The processes are picked up randomly. This solves the "message queue overflow" problem of one_queue discipline. However, the drawback is that the order of IQs is not maintained, i.e. matching IQs can be re-ordered (because one process can be slower than another) and this might be a problem in some cases. Care should be taken on choosing too large value for N because picking up a process from the pool has O(N) complexity. Anyway, in practice, seems like there is no much benefit to set N larger than 50. - parallel: for every matching IQ a process is created to execute the handler. This discipline is not recommended because uncontrolled processes creation is in general a bad idea.
It says IQ handler supports parallel execution This is argments of IQ Handler in document
gen_iq_handler:add_iq_handler(Type :: ejabberd_local | ejabberd_sm,
Host :: binary(),
Namespace :: binary(),
Module :: module(),
Function :: atom(),
IQDisc :: gen_iq_handler:type()) -> ok
However it's deprecated from gen_iq_handler.erl in master branch
%%====================================================================
%% Deprecated API
%%====================================================================
-spec add_iq_handler(module(), binary(), binary(), module(), atom(), any()) -> ok.
add_iq_handler(Component, Host, NS, Module, Function, _Type) ->
add_iq_handler(Component, Host, NS, Module, Function).
Question
I want to know how to make IQ handler parallel
- I read ejabberd document
- I searched the post which mentions this issue in stackoverflow and github
- I post same thing on ejabberd discussion : https://github.com/processone/ejabberd/discussions/4129
I expect parallel execution could be implemented using Erlang syntax but I don't know how to do that