From 7dd08d6d41fd77c447c99e07e62898ffcd757684 Mon Sep 17 00:00:00 2001 From: Darren Clark Date: Wed, 28 Aug 2019 11:19:05 -0400 Subject: [PATCH] Hardcode `:restart` handoff strategy GenServer.call was blocking the process in high load situations when a pod died. All our processes use the :restart strategy anyways, so just hardcode it in --- lib/swarm/tracker/tracker.ex | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/swarm/tracker/tracker.ex b/lib/swarm/tracker/tracker.ex index dec282e..a9a9fe9 100644 --- a/lib/swarm/tracker/tracker.ex +++ b/lib/swarm/tracker/tracker.ex @@ -856,25 +856,27 @@ defmodule Swarm.Tracker do debug("#{inspect(pid)} belongs on #{other_node}") # This process needs to be moved to the new node try do - case GenServer.call(pid, {:swarm, :begin_handoff}) do - :ignore -> - debug("#{inspect(name)} has requested to be ignored") - state - - {:resume, handoff_state} -> - debug("#{inspect(name)} has requested to be resumed") - {:ok, new_state} = remove_registration(obj, state) - send(pid, {:swarm, :die}) - debug("sending handoff for #{inspect(name)} to #{other_node}") - - GenStateMachine.cast( - {__MODULE__, other_node}, - {:handoff, self(), {name, meta, handoff_state, Clock.peek(new_state.clock)}} - ) - - new_state - - :restart -> +# All of our processes are meant to work with :restart, so skip the GenServer.call + +# case GenServer.call(pid, {:swarm, :begin_handoff}) do +# :ignore -> +# debug("#{inspect(name)} has requested to be ignored") +# state +# +# {:resume, handoff_state} -> +# debug("#{inspect(name)} has requested to be resumed") +# {:ok, new_state} = remove_registration(obj, state) +# send(pid, {:swarm, :die}) +# debug("sending handoff for #{inspect(name)} to #{other_node}") +# +# GenStateMachine.cast( +# {__MODULE__, other_node}, +# {:handoff, self(), {name, meta, handoff_state, Clock.peek(new_state.clock)}} +# ) +# +# new_state + +# :restart -> debug("#{inspect(name)} has requested to be restarted") {:ok, new_state} = remove_registration(obj, state) send(pid, {:swarm, :die}) @@ -883,7 +885,7 @@ defmodule Swarm.Tracker do :keep_state_and_data -> new_state {:keep_state, new_state} -> new_state end - end +# end catch _, err -> warn("handoff failed for #{inspect(name)}: #{inspect(err)}")