netudima commented on code in PR #4895:
URL: https://github.com/apache/cassandra/pull/4895#discussion_r3586659494
##########
src/java/org/apache/cassandra/metrics/ThreadLocalMetrics.java:
##########
@@ -374,26 +373,108 @@ static void recycleMetricId(int metricId)
lock.unlock();
}
- // there's no an obvious happens-before relation between
currentCounterValues[metricId] = 0 write we just did
- // and an initial read of the entry by a thread which updates the
reused metric
- // as a workaround we introduce a delay in recyling to provide the
write visibility in practice
- // even if it is not formally guaranteed by the JMM
- ScheduledExecutors.scheduledTasks.schedule(() -> {
+ freeMetricIdSetTracker.markAsFree(metricId);
+ }
+
+ @VisibleForTesting
+ static class FreeMetricIdSetTracker
+ {
+
+ private final Object freeMetricIdSetGuard = new Object();
+
+ private final BitSet freeMetricIdSet = new BitSet();
+
+ private final BitSet tickDelayedToFreeMetricIdSet = new BitSet();
+ private final BitSet tockDelayedToFreeMetricIdSet = new BitSet();
+
+ private BitSet delayedToFreeMetricIdSet = tickDelayedToFreeMetricIdSet;
+ private volatile boolean anythingToFree;
+
+ FreeMetricIdSetTracker()
+ {
+ this(true);
+ }
+
+ @VisibleForTesting
+ FreeMetricIdSetTracker(boolean scheduleTask)
+ {
+ if (scheduleTask)
+
ScheduledExecutors.scheduledTasks.scheduleAtFixedRate(this::triggerRecycling,
5, 5, TimeUnit.SECONDS);
Review Comment:
yes, agree, on demand task is better - no spare scheduling cycles, I've
applied the changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]