[erlang-questions] Erlang at Facebook - hibernation and gen_server

Davide Marquês nesrait@REDACTED
Tue Jun 30 19:41:16 CEST 2009


>
> This is really strange, that only gen_event supports explicit hibernate
> ie. returning {ok, Reply, State1, hibernate} from handle_call.
>
> gen_server and fsm lacks support for hibernate.
> --
> Witold Baryluk
>

That's the thing... from what I can tell gen_server's support for
hibernate is present and working!
http://www.erlang.org/doc/man/gen_server.html#Module:init-1

Using a gen_server looking like this:
init([Data]) ->
    {ok, #state{data=Data}}.

handle_call(hibernate, _From, State) ->
    {reply, going_to_hibernate, State, hibernate};
handle_call(get_state, _From, State) ->
    {reply, State, State};
handle_call(_Request, _From, State) ->
    {reply, ok, State}.

We can see a gen_server hibernating:
Eshell V5.7.2  (abort with ^G)
1> hibernate:start_link(initial_state).
{ok,<0.34.0>}
2> gen_server:call(hibernate, get_state).
{state,initial_state}
3> erlang:process_info(whereis(hibernate), total_heap_size).
{total_heap_size,233}
4> gen_server:call(hibernate, hibernate).
going_to_hibernate
5> erlang:process_info(whereis(hibernate), total_heap_size).
{total_heap_size,31}
6> gen_server:call(hibernate, get_state).
{state,initial_state}
7> erlang:process_info(whereis(hibernate), total_heap_size).
{total_heap_size,267}

It seems to work, so I'm left to wonder what "incompatibility"
was described in Eugene's presentation.

Cheers,
:Davide


More information about the erlang-questions mailing list