I have 2 GenServers, (there is no backpressure)
I would describe 2 main methods, from first GenServer (Recording.WorkerStarter
).
def handle_info(:request, state) do
schedule_fetch_call(state.sleep)
ping_time_state = Map.put(state, :running, %{datetime: DateTime.utc_now(), worker: true})
ConCache.get(:do_camera_request, state.camera.name)
|> shoot_a_request(ping_time_state, Recording.Worker)
{:noreply, ping_time_state}
end
def shoot_a_request(true, state, worker) do
ConCache.put(:do_camera_request, state.camera.name, false)
DynamicSupervisor.start_child(General.Supervisor, {worker, state})
end
and on the other GenServer (Recording.Worker
) there is only one important callback
def handle_info(:fetch_and_process, state) do
case FetchMeJpeg.request(state.camera, state.running.datetime) do
{:failed, _requested_at} ->
ConCache.put(:do_camera_request, state.camera.name, true)
{:stop, :shutdown, state}
{:ok, body, requested_at} ->
SeaweedMe.post(state.camera.name, body, requested_at)
BroadcastMe.push(state.camera.name, body, requested_at)
ConCache.put(:do_camera_request, state.camera.name, true)
{:stop, :normal, state}
end
end
I am running 2 Recording.WorkerStarter
which are adding Recording.Worker
.
now in Recording.Worker
I have 3 important calls.
- FetchMeJpeg.request(state.camera, state.running.datetime)
- SeaweedMe.post(state.camera.name, body, requested_at)
- BroadcastMe.push(state.camera.name, body, requested_at)
I have seen some use cases where People have done event management and when 1. got succeeded, they bypass the results to 2. and 3. as events.
I am keen to know what is the benefit of this?
the above consecutive calls are working fine without any event passing.
But I am going to increase the number from 2 to 1000 for adding Recording.WorkerStarter
.
my question is, switching to events can make performance optimization?
and what are the event management tools are available? GenEvent? gproc? GenStage?