Anonymous avatar Anonymous committed 8638bb8

Removing phase cache for memory-consumption reasons

Comments (0)

Files changed (3)

src/luke_flow.erl

 
 init([Client, FlowId, FlowDesc, FlowTransformer, Timeout]) ->
     process_flag(trap_exit, true),
-    {ok, CachePid} = luke_flow_cache:start_link(),
     Tref = case Timeout of
                infinity ->
                    undefined;
                    {ok, T} = timer:send_after(Timeout, flow_timeout),
                    T
            end,
-    case start_phases(FlowDesc, CachePid, Timeout) of
+    case start_phases(FlowDesc, Timeout) of
         {ok, FSMs} ->
             {ok, executing, #state{fsms=FSMs, flow_id=FlowId, flow_timeout=Timeout, client=Client, xformer=FlowTransformer, tref=Tref}};
         Error ->
     {ok, StateName, State}.
 
 %% Internal functions
-start_phases(FlowDesc, CachePid, Timeout) ->
-    start_phases(lists:reverse(FlowDesc), length(FlowDesc) - 1, CachePid, Timeout, []).
+start_phases(FlowDesc, Timeout) ->
+    start_phases(lists:reverse(FlowDesc), length(FlowDesc) - 1, Timeout, []).
 
-start_phases([], _Id, _CachePid, _Timeout, Accum) ->
+start_phases([], _Id, _Timeout, Accum) ->
     {ok, Accum};
-start_phases([{PhaseMod, Behaviors, Args}|T], Id, CachePid, Timeout, Accum) ->
+start_phases([{PhaseMod, Behaviors, Args}|T], Id, Timeout, Accum) ->
     NextFSM = next_fsm(Accum),
     case proplists:get_value(converge, Behaviors) of
         undefined ->
             case luke_phase_sup:new_phase(Id, PhaseMod, Behaviors, NextFSM, self(),
-                                          CachePid, Timeout, Args) of
+                                          Timeout, Args) of
                 {ok, Pid} ->
                     erlang:link(Pid),
-                    start_phases(T, Id - 1, CachePid, Timeout, [Pid|Accum]);
+                    start_phases(T, Id - 1, Timeout, [Pid|Accum]);
                 Error ->
                     Error
             end;
         InstanceCount ->
-            Pids = start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, self(), CachePid,
+            Pids = start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, self(),
                                            Timeout, Args, InstanceCount),
-            start_phases(T, Id - 1, CachePid, Timeout, [Pids|Accum])
+            start_phases(T, Id - 1, Timeout, [Pids|Accum])
     end.
 
 collect_output(FlowId, Timeout, Accum) ->
          end
  end.
 
-start_converging_phases(Id, PhaseMod, Behaviors0, NextFSM, Flow, CachePid,
+start_converging_phases(Id, PhaseMod, Behaviors0, NextFSM, Flow,
                         Timeout, Args, Count) ->
     Behaviors = [normalize_behavior(B) || B <- Behaviors0],
-    Pids = start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, Flow, CachePid,
+    Pids = start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, Flow,
                                    Timeout, Args, Count, []),
     [Leader|_] = Pids,
     lists:foreach(fun(P) -> luke_phase:partners(P, Leader, Pids) end, Pids),
     Pids.
 
-start_converging_phases(_Id, _PhaseMod, _Behaviors, _NextFSM, _Flow, _CachePid,
+start_converging_phases(_Id, _PhaseMod, _Behaviors, _NextFSM, _Flow,
                         _Timeout, _Args, 0, Accum) ->
     Accum;
-start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, Flow, CachePid,
+start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, Flow,
                         Timeout, Args, Count, Accum) ->
-    case luke_phase_sup:new_phase(Id, PhaseMod, Behaviors, NextFSM, Flow, CachePid,
+    case luke_phase_sup:new_phase(Id, PhaseMod, Behaviors, NextFSM, Flow,
                                   Timeout, Args) of
         {ok, Pid} ->
             erlang:link(Pid),
-            start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, Flow, CachePid,
+            start_converging_phases(Id, PhaseMod, Behaviors, NextFSM, Flow,
                                     Timeout, Args, Count - 1, [Pid|Accum]);
         Error ->
             throw(Error)

src/luke_phase.erl

 -include_lib("eunit/include/eunit.hrl").
 
 %% API
--export([start_link/8,
+-export([start_link/7,
          complete/0,
-         partners/3,
-         cache_value/2,
-         check_cache/1]).
+         partners/3]).
 
 %% Behaviour
 -export([behaviour_info/1]).
 behaviour_info(_) ->
     undefined.
 
-start_link(PhaseMod, Id, Behaviors, NextPhases, Flow, CachePid,
-           Timeout, PhaseArgs) ->
-    gen_fsm:start_link(?MODULE, [Id, PhaseMod, Behaviors, NextPhases, Flow, CachePid,
+start_link(PhaseMod, Id, Behaviors, NextPhases, Flow, Timeout, PhaseArgs) ->
+    gen_fsm:start_link(?MODULE, [Id, PhaseMod, Behaviors, NextPhases, Flow,
                                  Timeout, PhaseArgs], []).
 
 complete() ->
 partners(PhasePid, Leader, Partners) ->
     gen_fsm:send_event(PhasePid, {partners, Leader, Partners}).
 
-cache_value(Key, Value) ->
-    case erlang:get(flow_cache_pid) of
-        undefined ->
-            ok;
-        CachePid ->
-            luke_flow_cache:cache_value(CachePid, Key, Value)
-    end.
-
-check_cache(Key) ->
-    case erlang:get(flow_cache_pid) of
-        undefined ->
-            not_found;
-        CachePid ->
-            luke_flow_cache:check_cache(CachePid, Key)
-    end.
-
-init([Id, PhaseMod, Behaviors, NextPhases, Flow, CachePid, Timeout, PhaseArgs]) ->
-    erlang:put(flow_cache_pid, CachePid),
+init([Id, PhaseMod, Behaviors, NextPhases, Flow, Timeout, PhaseArgs]) ->
     case PhaseMod:init(PhaseArgs) of
         {ok, ModState} ->
             Accumulate = lists:member(accumulate, Behaviors),

src/luke_phase_sup.erl

 
 %% API
 -export([start_link/0,
-         new_phase/8]).
+         new_phase/7]).
 
 %% Supervisor callbacks
 -export([init/1]).
 
-new_phase(Id, PhaseMod, Behavior, NextPhases, Flow, CachePid,
+new_phase(Id, PhaseMod, Behavior, NextPhases, Flow,
           Timeout, PhaseArgs) when is_atom(PhaseMod),
                                    is_list(PhaseArgs) ->
-    start_child(PhaseMod, [Id, Behavior, NextPhases, Flow, CachePid, Timeout, PhaseArgs]).
+    start_child(PhaseMod, [Id, Behavior, NextPhases, Flow, Timeout, PhaseArgs]).
 
 start_link() ->
     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.