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

Davide Marquês <>
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!

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).
2> gen_server:call(hibernate, get_state).
3> erlang:process_info(whereis(hibernate), total_heap_size).
4> gen_server:call(hibernate, hibernate).
5> erlang:process_info(whereis(hibernate), total_heap_size).
6> gen_server:call(hibernate, get_state).
7> erlang:process_info(whereis(hibernate), total_heap_size).

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


More information about the erlang-questions mailing list