[erlang-questions] Is gen_server behavior in R14B hibernate friendly?

Davide Marquês <>
Thu Nov 11 02:32:45 CET 2010


Hi Zvi,

Check out the attached gen_server_light module. :)
IIRC it differs from gen_server in that the handle_call/3 supports a new
return value:
    {noreply, NewState, {call_and_hibernate, {Server, Req, ReqTimeout}}};
which instructs it to issue a call to another server and then hibernate
while waiting for the reply.
When that reply comes (or the ReqTimeout is reached) handle_reply/2 is
called enabling the
caller to proceed with what it was doing.

Hope the code still works. :)

Cheers,
:Davide

On Sun, Nov 7, 2010 at 3:03 PM, Ulf Wiger <>wrote:

>
> Hi Zvi,
>
> Actually, nowadays, gen_server supports 'hibernate' as a special
> value of the internal timeout, so your server callbacks can instruct
> the main loop to go into hibernation between messages.
>
> It is true that hibernate/3 doesn't have a timeout, but OTOH, it is
> easy enough to start a timer that will send a message, bringing
> you out of hibernation, after a specified time.
>
> BR,
> Ulf W
>
> On 6 Nov 2010, at 15:51, Zvi wrote:
>
> > Hi,
> > I re-reading Erlang at Facebook slides. And found this. Is this still
> > an issue?
> >
> > Zvi
> >
> > "Hibernation
> > ▪
> > Drastically shrink memory usage with erlang:hibernate/3
> > ▪ Throws away the call stack
> > ▪ Minimizes the heap
> > ▪ Enters a wait state for new messages
> > ▪ “Jumps” into a passed-in function for a received message
> > ▪ Perfect for a long-running, idling HTTP request handler
> > ▪ But ... not compatible with gen_server:call (and gen_server:reply)
> > ▪ gen_server:call has its own receive() loop
> > ▪ hibernate() doesn’t support have an explicit timeout
> > ▪ Fixed with a few hours and a look at gen.erl"
> >
> > ________________________________________________________________
> > erlang-questions (at) erlang.org mailing list.
> > See http://www.erlang.org/faq.html
> > To unsubscribe; mailto:
> >
>
> Ulf Wiger, CTO, Erlang Solutions, Ltd.
> http://erlang-solutions.com
>
>
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20101111/055fdbc1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gen_server hibernate.zip
Type: application/zip
Size: 11801 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20101111/055fdbc1/attachment.zip>


More information about the erlang-questions mailing list