[erlang-questions] Using gen_server or writing a new behavior
Ciprian Dorin, Craciun
ciprian.craciun@REDACTED
Fri Jan 16 18:15:32 CET 2009
On Fri, Jan 16, 2009 at 6:30 PM, Christian <chsu79@REDACTED> wrote:
> On Fri, Jan 16, 2009 at 16:21, Ciprian Dorin, Craciun
> <ciprian.craciun@REDACTED> wrote:
>> Hello all!
>>
>> I have a somehow philosophycal question about OTP, mainly about
>> gen_server...
>>
>> I want to write my own HTTP framework, the main focus now being
>> the request handlers... So:
>> * I created a request handler supervisor, which managed the
>> request handlers;
>> * each connection handler after resolving the request handler,
>> delegates the request to it;
>
> This is how I have it:
>
> * each request is a process that look at the method, url, etc,
> dispatch to functions that parse what is needed, such as posted bodies
> or query args.
> * all the data goes into a function that calls plain ordinary
> gen_servers (if they need to at all!), still in the same process
> * the result is sent to a template function that renders the result
> values to something htmlish, and still in the same process.
What do you mean by "calls plain ordinary gen_servers still in the
same process"? Calling a gen_server implies sending a message to a
gen_server process, right?
> This is because sending each request directly into a gen_server will
> limit concurrency. While it processes one requests, others could be
> _waiting to be served_. The latter being the problem.
Yes, indeed this would happen, and this would be an
disadvantage... (Limiting concurency, adding message passing overhead)
But there are two reasons I would like to do this (that is using
gen_server like processes):
* first is that it looks more Erlang-ish, than dispatching the
request to a module:function... (the Erlang way is have lot's of
processes right?);
* second, I could create multiple request handlers that are used
in a round robin fashion; (and thus control the load on a given set of
URLs, without having fancy code behind it, just by limiting the number
of registered handlers);
As a side note, this is what bothers me with most Erlang http
servers: they use module:callback dispatchers and not processes... It
adds performance, but reduces flexibility / OTP-way of doing things
(if there is such a thing)...
> Additionally, my way the gen_servers that I do need, for ordering
> access to some resources, have no dependencies on http requests. They
> instead expose the sanest messages possible for the manipulations to
> the resource they keep.
>
> You should probably look into "beepbeep" since it does pretty much
> exactly what i describe. It also uses erlydtl which is a pretty cool
> template language.
I'll look into them. Thanks,
Ciprian Craciun.
More information about the erlang-questions
mailing list