From 4ba1223c3f99d2dcc4be9b6d42f1d35c3c13b262 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Tue, 26 Oct 2021 12:59:35 -0500 Subject: [PATCH] hark-store: cap size of half-open timeboxes Prevents unnecessarily large timeboxes from accumulating, which can negatively impact performance. --- pkg/garden/app/hark-store.hoon | 5 +++-- pkg/garden/tests/app/hark-store.hoon | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/garden/app/hark-store.hoon b/pkg/garden/app/hark-store.hoon index adef676f1..651a1c6a5 100644 --- a/pkg/garden/app/hark-store.hoon +++ b/pkg/garden/app/hark-store.hoon @@ -403,11 +403,12 @@ (~(put by half-open) bin now.bowl) =/ existing (get-lid archive/time bin) =/ new (merge-notification existing note) + =? half-open (lth 30 (lent body.new)) + (~(del by half-open) bin) =. poke-core (put-lid archive/time bin new) =. poke-core (del-lid lid bin) - =. poke-core (give %archived now.bowl unseen+~ (~(got re archive) time bin)) - =. poke-core (give %archived now.bowl seen+~ (~(got re archive) time bin)) + =. poke-core (give %archived time lid (~(got re archive) time bin)) $(bins t.bins) :: ++ read-count diff --git a/pkg/garden/tests/app/hark-store.hoon b/pkg/garden/tests/app/hark-store.hoon index fe06b6d01..c42f5334c 100644 --- a/pkg/garden/tests/app/hark-store.hoon +++ b/pkg/garden/tests/app/hark-store.hoon @@ -30,7 +30,7 @@ [%read-count place] :: +$ state - $: %8 + $: %9 places=(map place:hark stats:hark) seen=timebox:hark unseen=timebox:hark @@ -87,4 +87,17 @@ =/ actual-archive=notification:hark (~(got re archive.state) (add *time ~s1) bin) (expect-eq !>(expected-archive) !>(actual-archive)) +:: +++ test-half-open-capped + =| run=@ud + |- + ?: =(run 31) + =+ !<(=state on-save:agent) + (expect-eq !>(~) !>(half-open.state)) + =^ movs agent + (~(on-poke agent (bowl run)) %hark-action !>((add-note run))) + =^ mavs agent + (~(on-poke agent (bowl run)) %hark-action !>(read-count)) + $(run +(run)) +:: --