[erlang-questions] gen_server vs gen_fsm

Chandru chandrashekhar.mullaparthi@REDACTED
Mon Oct 8 10:52:58 CEST 2007


Hi,

On 08/10/2007, YC <yinso.chen@REDACTED> wrote:
> Hi all -
>
> I have a few newbie questions regarding gen_server and gen_fsm - I couldn't
> find the answers easily though I'm sure they exists somewhere; would
> appreciate pointers and sharing of experiences in designs :)
>
> * are gen_fsm also a "server"?  It seems like gen_fsm is used to manage a
> process that have multiple stages to fulfill its job, where gen_server by
> and large has only one state, is that correct?  If not, what are the
> differences?

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

> * I've read that the best way to handle multiple requests is to use
> {noreply, State} in conjunction to spawn worker processes to handle the
> request - should the worker process also be gen_server or gen_fsm?  For
> example, what should a web server's worker process be?

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.

> * 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.

cheers
Chandru



More information about the erlang-questions mailing list