From 1ad7d4b12bab4acb524f7e828ddf60fe62ba5e8e Mon Sep 17 00:00:00 2001 From: mck Date: Tue, 19 May 2020 17:14:53 +0200 Subject: [PATCH] When there are no broadcasters and no known subscriptions, only check for updated events once per minute This will reduce table scans on diagnostic_event_subscription when reaper is distributed and diagnostics not otherwise used/subscribed to. Based off findings from https://github.com/thelastpickle/cassandra-reaper/issues/896 --- .../service/DiagEventSubscriptionService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/server/src/main/java/io/cassandrareaper/service/DiagEventSubscriptionService.java b/src/server/src/main/java/io/cassandrareaper/service/DiagEventSubscriptionService.java index 7a26b92b1..b8e74187c 100644 --- a/src/server/src/main/java/io/cassandrareaper/service/DiagEventSubscriptionService.java +++ b/src/server/src/main/java/io/cassandrareaper/service/DiagEventSubscriptionService.java @@ -84,6 +84,7 @@ public final class DiagEventSubscriptionService { private final AppContext context; private final HttpClient httpClient; private final ScheduledExecutorService scheduler; + private final AtomicLong lastUpdateCheck = new AtomicLong(0); private Set subsAlwaysActive; @@ -135,7 +136,13 @@ public void subscribe(DiagEventSubscription sub, EventOutput eventOutput, String private synchronized void updateEnabledEvents() { if (context.isDistributed.get()) { - updateEnabledEvents(Collections.emptySet()); + if (!BROADCASTERS.isEmpty() || null == subsAlwaysActive || !subsAlwaysActive.isEmpty() + // when there are no broadcasters and no known subscriptions, only check for updated events once per minute + || (System.currentTimeMillis() - lastUpdateCheck.get()) > TimeUnit.MINUTES.toMillis(1)) { + + lastUpdateCheck.set(System.currentTimeMillis()); + updateEnabledEvents(Collections.emptySet()); + } } }