From 355d5591952b6ce7f8e1e78d95601bebb38ef372 Mon Sep 17 00:00:00 2001 From: Alain Zscheile Date: Sun, 27 Nov 2022 21:52:41 +0100 Subject: [PATCH] coalesce drop notifications --- lib/floof.ex | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/floof.ex b/lib/floof.ex index 3dd95eb..2ae8e06 100644 --- a/lib/floof.ex +++ b/lib/floof.ex @@ -94,6 +94,11 @@ defmodule Floof do {backlog, sesskey} + {:fwddrop, dcdhash} -> + to_drop = coalesce_fwddrops(MapSet.new(dcdhash)) + :ok = send_summary(client, :drop, to_drop) + {backlog, sesskey} + {:SessionPushed, sesskey} -> sesskeys = coalesce_sesspushes([sesskey]) [sesskey | _] = sesskeys @@ -180,9 +185,9 @@ defmodule Floof do {:xfer, xf} -> mhash = Floof.Message.emit(xf) - # notify the remote end that we successfully consumed the message - # non-fatal if this fails - send_summary(client, :drop, [mhash]) + # the following indirection is necessary + # to reduce the amount of 'drop' notifications + send(self(), {:fwddrop, mhash}) {backlog, sesskey} end end @@ -210,6 +215,14 @@ defmodule Floof do end end + defp coalesce_fwddrops(to_drop) do + receive do + {:fwddrop, dcdhash} -> coalesce_fwddrops(MapSet.put(to_drop, dcdhash)) + after + 10 -> to_drop + end + end + defp partition_hashes(xs) do xs |> Floof.DistributorSeen.have_we_multi()