Hi,
I wrote a module that uses the muc_filter_message hook, all it does is making an http request on every message (I don't need the result of this request, it's a shoot and forget best effort kind of thing). I am new to erlang and ejabberd and my question is simple, should I make the request synchronously or use spawn to do that? How "heavy" is spawning a new process for every message? Does it make sense?
Thanks,
Adam
Let's take spawning and
Let's take spawning and terminating an erlang process for each xmpp message as the baseline. You could implement that and test how well it behaves.
If you want an alternative that doesn't spawn a process per stanza, try this:
1. At module start, spawn an erlang process that waits in an endless loop. Register that process with name "yourmodule_yourvhost"
2. When the hooked function is called, it just sends an erlang message to that process: yourmodule_yourvhost ! {handlethis, Content}
3. Your process awaits reception of those messages, performs its duty (HTTP request), and continues the loop.
That erlang process has a queue where the erlang messages you send await automatically. This means that only one HTTP request is done at each time, as you have only one process in that duty.
There are examples in ejabberd, see the loop in mod_vcard.