Skip to content

Commit

Permalink
When there are no broadcasters and no known subscriptions, only check…
Browse files Browse the repository at this point in the history
… 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 #896
  • Loading branch information
michaelsembwever committed May 27, 2020
1 parent f54cc11 commit 1ad7d4b
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagEventSubscription> subsAlwaysActive;

Expand Down Expand Up @@ -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());
}
}
}

Expand Down

0 comments on commit 1ad7d4b

Please sign in to comment.