<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>Hello! </div><div><br class="webkit-block-placeholder"></div><div>Good (and well formed!) question from Dave and good aswers in the erlang-questions list!</div><div><br class="webkit-block-placeholder"></div><div>There's one more alternative, namely plain_fsm behaviour by Ulf Wiger, which could be nice fit for the problem. It does away with the "complexities" of gen_fsm but still is suitable for supervision tree. Have a look at:</div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Verdana" size="4" style="font: 13.0px Verdana"><b><a href="http://tinyurl.com/yu6jha">http://tinyurl.com/yu6jha</a></b></font></div></div><div><a href="http://jungerl.cvs.sourceforge.net/jungerl/jungerl/lib/plain_fsm/">http://jungerl.cvs.sourceforge.net/jungerl/jungerl/lib/plain_fsm/</a></div><div><br class="webkit-block-placeholder"></div><div>Cheers,</div><div>Jani Launonen</div><div><br></div><br><div><div>Dave Smith kirjoitti 15.1.2008 kello 20.51:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Greetings,</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I'm using gen_fsm to manage a socket connection, and have a question</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">about how one SHOULD use gen_fsm for this purpose. I'm specifically</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">using the "active" mode for the socket, so I'm currently receiving</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">events via the handle_info/3 callback. I understand why the socket</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">events arrive there, but I wonder what the best way to pass the event</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">along to the actual FSM is. I see there being 3 possible options:</div></blockquote><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">1. Receive socket events on a dedicated process and pass events into</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">gen_fsm via that process. Upside is that this provides nice separation</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">of socket and fsm logic. Downside there is that I'm doubling the</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">number of processes -- i.e. i had one process per socket, now I have</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">two. That's not a big problem with a couple of thousand connections,</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">but once I'm in the 20k-30k connections realm, I'm not quite sure what</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">the implications of doubling the number of processes is. Is it</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">"normal" in a production system to run 100k+ processes? Note: I'm</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">still recovering from pthreads land, where 100k+ theads is a scary,</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">scary thing -- so maybe this concern over # of processes is a</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">threading world "hangover" :)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">2. Receive socket events in handle_info and invoke</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">gen_fsm:send_event() from there. This seems like the "obvious"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">approach, but it feels wrong -- I'm already in process and don't</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">really want to queue up another event. Again, possibly a "hangover"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">from non-Erlang land.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">3. Receive socket events in handle_info, then do a</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">?MODULE:StateName({socket_event ...}, State). Avoids (perceived)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">overhead of approach #3, but...is this a good idea?!</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hopefully this isn't a stupid/obvious question -- I'm finding that</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">erlang has a tendency to turn "common sense" on its head (in a good</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">way). Any guidance from the gurus would be happily accepted.. :)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">D.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">erlang-questions mailing list</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a></div> </blockquote></div><br></body></html>