[erlang-questions] gen_server vs gen_fsm

YC yinso.chen@REDACTED
Mon Oct 8 11:13:07 CEST 2007


Hi -

Thanks for the quick response, please see inline.

On 10/8/07, Chandru <chandrashekhar.mullaparthi@REDACTED> wrote:

> > A gen_fsm helps you implement the logic for a finite state machine.
> > You can implement a FSM using gen_server but gen_fsm makes it much
> > more easier and your code will be more structured and easier to read.
>
> > > * when should one use gen_fsm?  and when should one use a gen_server?
>
> > Use a gen_server when you want a long lived process which reacts to
> > events. Use a gen_fsm to implement state machines. See
> > http://en.wikipedia.org/wiki/Finite_state_machine


When I think of state machine two primary types of example comes to mind:

1) the machine will generate the end result in one call as the input stream
contains enough information to allow the machine to finish its processing;
for example, a regular expression match

2) the machine will reach its end state only after multiple calls as each
call changes the state; for example, an e-commerce website.

Which type is gen_fsm suited for?  To me, the 1st type is not a server,
where the second type is, and hence my confusion about its suitability.  As
you say that gen_server is better suited for long lived processes, is
gen_fsm not suited to implement the logic behind an e-commerce site?

> A web server's worker process doesn't have to be a gen_server or a
> > gen_fsm. It just needs to be a module which given the HTTP request,
> > does some processing and returns some content to the HTTP client.


I see.  Are there disadvantages to use gen_server or gen_fsm in this case?
Overkill?

> > * what's a good way to test the spawning to make it that it works?  I
> mean,
> > > are there available tools to simplify the process?
>
> > Sorry - I don't understand your question.


Sorry - I simply meant to ask if there are tools within Erlang that would
help with simulating load testings, such as the ab tool.

Thanks,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071008/c9baabe3/attachment.htm>


More information about the erlang-questions mailing list