[erlang-questions] valid use for gen_server?

Pablo Platt <>
Tue Oct 5 01:02:31 CEST 2010


>Pablo Platt <> wrote:


>pp> I see two options to implement the above, gen_event or custom event
>pp> module.  What bothers me in gen_event is that it executes handlers
>pp> in its own context.  If events are rare that shouldn't be a problem
>pp> but if each IM message will fire several events wouldn't this flood
>pp> the gen_event server?

>Using gen_event, if you want to apply backpressure, you have the option
>of sending the events synchronously.

>pp> I can use a custom event module that saves events and handlers in
>pp> ETS table and call functions dynamically with Module:Function(Args).
>pp> This also doesn't feel right because each IM message will require
>pp> several ETS lookups and dynamic functions calls which according to
>pp> the efficiency guide are are 6 times slower than normal calls.

>Er, sorry, but this sounds like premature worrying.  If handling an
>event requires N reductions and therefore N units of time(*), then the
>cost of handling the same event using the dynamic functions calls would
>be (N - several) + (6 * several) ... which is likely to be really,
*>really* close to N.

>-Scott

>(*) Which isn't exactly true, but it's a good approximation.

If I have ten events per message I need to make ten ETS calls and than add the 
dynamic function calls to it.

On a busy system, can't this add up?



      


More information about the erlang-questions mailing list