[erlang-questions] hibernate/timeout

Ulf Wiger <>
Fri Jun 15 08:40:25 CEST 2007


Hi Damien,

The hibernate/3 function is really useful when you have
lots of long lived processes, and you need to save memory.

The timeout clause in the receive is not relevant to
hibernate, because you cannot hibernate and wait in
a receive at the same time. You can do a receive with
a timeout, and go into hibernation after a certain time,
but I think it's better to simply hibernate first, if you
suspect that it may be a while before the next message
comes in. One simple way of using it might be to always
hibernate when transitioning into a stable state.

And, yes, you should use the timer BIFs rather than the
timer module.

BR,
Ulf W

2007/6/14, Damien Morton <>:
> Hello,
>
> Im new to the list, so... hello everyone.
>
> Wanted to ask a question about managing large numbers of very
> lightweight processes.
>
> Ive discovered the hibernate() function, which should prove usefull as
> most of the processes I will be using will be asleep for extended
> periods of time - minutes, hours and even days, though this sleep will
> very often be interrupted.
>
> Im wondering, however, if a process which is hibernating will timeout if
> its receive loop has a timeout clause, or whether, once placed into
> hibernation, it will remain there until an external process sends it a
> message.
>
> My intention was to make processes hibernate after a period of time in
> which they receive no messages, and to then wake up after a certain
> period of time.
>
> Ive had a look at the timer module, which seems to use ets as a priority
> queue. Id rather stick with the built-in timeout mechanism, if possible.
> >From what I read, its timer-wheel implementation is very efficient.
>
> Thanks,
>
> Damien Morton
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list