[ejabberd] Feedback on my "Facebook Suspend implementation?

David Laban alsuren at gmail.com
Thu Apr 4 20:13:29 MSK 2013



Further to http://www.ejabberd.im/node/5075 and my previous posts:

I have implemented a hybrid of Facebook's Suspend extension and google's queue 
extension. The idea is to stop the server from waking up the iPhone client 
with stanzas when it is in the "background" state (too many wakeups in a given 
10 minute period will cause the OS to kill the app).

I have squashed it into a single patch against ejabberd 2.1.12.
It can be found at:

https://github.com/alsuren/ejabberd/commits/suspend


The design is currently:

* In ejabberd_c2s, if <iq><sleep/></iq> is received:
** wrap sockmod and socket in ejabberd_suspend 
   (which implements the same interface, but queues up all outgoing stanzas)

* When<iq><flush/></iq> is received:
** ejabberd_suspend is told to flush all queued stanzas.

* When <iq><wake/></iq> is received:
** ejabberd_suspend flushes all queued stanzas, then returns the original
    sockmod and socket that it originally wrapped.



This is my first big erlang project, so I would like some feedback on it. 
Specifically:

* ejabberd_suspend is currently an FSM with exactly one state, and a list of
  queued stanzas stored in its #suspend_state struct.
** Is there an algorithmic way to convert this into a gen_server, or is a
    manual refactor required?
** How much more efficient is gen_server than gen_fsm?
** Is there something more efficient than gen_server that I can use?

* I am currently not hibernating ejabberd_suspend processes.
** How much could I gain by suspending?
** Is there any way to achieve the same effect without creating a new process
    for each connected+backgrounded iPhone?

* I haven't yet pushed my spec to standards at . 
** Can anyone think of any optimisations to the protocol that would make it
    more efficient?

* I haven't had any code review from experienced erlangers yet
** Can someone have a glance at my code and see if it looks sane?


David.


More information about the ejabberd mailing list