[erlang-questions] gen_fsm and active sockets

Dave Smith dizzyd@REDACTED
Tue Jan 15 21:46:28 CET 2008

On Jan 15, 2008 12:38 PM, igwan <igwan@REDACTED> wrote:
> Hello,
> Dave Smith wrote :
> Using the 'active' mode means you have no way to control the flow of
> data coming from the network. They will accumulate as messages in your
> processes' mailboxes if you can't keep up, and severely alter
> responsivity of the system. So be sure you can handle the full load,
> especially if you want to do much computation on incoming data. However,
> in practice it is likely you'll be more limited by the cpu time consumed
> by the VM just to receive packets than by the actual computation
> performed by your processes. (was the case in R11B-5, see
> http://www.nabble.com/gen_tcp-receving-slow-tt12870823.html , haven't
> checked with R12B yet).

I understand your point -- however, my overall question remains even
using {active, once} with the socket.

> It would not only double the number of process (that's a memory impact),
> but also the number of messages (a cpu time impact).

Agreed -- processes and # of messages both grow with approach 1.
However, processes and messages are a primary paradigm in Erlang; it
would be remiss of me to not consider using them to solve this
problem, I think.

> > 3. Receive socket events in handle_info, then do a
> > ?MODULE:StateName({socket_event ...}, State). Avoids (perceived)
> > overhead of approach #3, but...is this a good idea?!
> >
> This is how I would do (and have done for a HTTP server). It has very
> little overhead (just a function call) and keeps the code readable. But
> i'll let the gurus give you a definitive advice :)

Actually I believe it's more expensive than just a straight function
call -- it boils down to a call to "apply" unless I'm mistaken. Not
sure how the overhead of invoking apply compares to message passing...

Thanks, igwan.


More information about the erlang-questions mailing list