Elixir using ExActor is there a way to hibernate depending on conditions -
i learning elixir develop auction web site. have worker each auction, when worker started might go hibernate immediatly, during last n minutes before end of auction don't want worker hibernate each time bid received (tell me if wrong might not efficient).
i have started developing basic genserver otp (handle_call, handle_info ...) , refactoring exactor , fsm (both saša jurić), , trying apply cqrs/es.
is there way achieve using exactor , not going handle_call "basics" ?
i achieve similar :
{:reply, ...}
when there less 10 minutes left until auction's end.
{:reply, ..., :hibernate}
when there more 10 minutes left until auction's end.
in erlang, hibernation following things:
- discard process call stack
- do garbage collection
- after that, process memory might reduced values lower minimal heap size
- process wakes on message (if there messages in mailbox, wakes immediately)
- on waking up, there garbage collection, restores normal process size
hibernation , waking quite cpu intensive , saves small amounts of memory. advice either not use @ or make performance tests see, if gain worth it. if have millions of auction processes , new messages rarely, there might memory gain, don't expect big.
you can switch between hibernate depending on conditions. enough write in normal otp:
case time_left > ten_minutes true -> {:reply, new_state, :hibernate} false -> {:reply, new_state} end
in exactor be:
defcall your_funcion(args), state: state, ... case time_left > ten_minutes true -> set_and_reply(new_state, :hibernate) false -> set_and_reply(new_state, timeout) end end
macros reply
take optional argument, either timeout value or :hibernate
atom.
ps. might interested in article real time bidding in erlang.
Comments
Post a Comment