[erlang-questions] When to use gen_server?

eigenfunction emeka_1978@REDACTED
Thu Jan 12 13:17:32 CET 2012

Now i see. That makes sense.
Thank you for the explanation.

On 12 Jan., 12:22, Robert Raschke <rtrli...@REDACTED> wrote:
> On Thu, Jan 12, 2012 at 10:35 AM, eigenfunction <emeka_1...@REDACTED>wrote:
> > > If you don't need to serialize your data
> > > processing requests, don't bother with all that.
> > Could you pls elaborate more on that? I, Like the OP , sometimes
> > have a hard time making a difference between a gen_server and a normal
> > process,
> > and i end up using normal processes and think that i am doing
> > something wrong.
> > Can anyone give an example of a case where a gen_server is more useful
> > than a normal
> > process?
> A gen_server wraps up a resource through client-server interaction. From
> the documentation (http://www.erlang.org/doc/design_principles/gen_server_concepts.html#...
> ):
> "The client-server model is characterized by a central server and an
> arbitrary number of clients. The client-server model is generally used for
> resource management operations, where several different clients want to
> share a common resource. The server is responsible for managing this
> resource."
> The key here is that you want multiple clients to share one common
> resource. Thus you have to provide a way to handle multiple requests from
> your clients in a defined way. The gen_server does that for you.
> Sometimes your model does not need a shared common resource, instead you
> bring lots of processes to life that do work.
> For example, I use a gen_server to handle comms with a C Node that runs Lua
> code. This means I don't have to worry about asynchronous requests in my C
> or Lua code.
> I have another component that handles messages from RabbitMQ and here I
> simply care about handling the message, so I kick of a process to deal with
> the message. (This is low-volume messaging, in case you start wondering
> about the sanity of this approach :-)
> Robby
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list