netudima commented on code in PR #4003: URL: https://github.com/apache/cassandra/pull/4003#discussion_r2032080831
########## src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java: ########## @@ -855,4 +855,319 @@ public String toString() return "[" + min + ',' + max + ']'; } } + + interface MetricCleaner + { + void clean(); + } + + private static class BucketsPhantomReference extends PhantomReference<Object> implements MetricCleaner + { + private final MetricCleaner cleaner; + + public BucketsPhantomReference(ReferenceQueue<? super Object> q, MetricCleaner cleaner) + { + super(Thread.currentThread(), q); + this.cleaner = cleaner; + } + + public void clean() + { + cleaner.clean(); + } + } + + /** + * Writes are exclusive to the thread-local buckets, so we can use a single updater for all threads. + * Readers will see a consistent view of the buckets and could be blocked for a while. + * <p> + * The class is aslso being tracked by a phantom reference queue to release the accumulated buckets when the thread is dead. + */ + protected class BucketsThreadLocal + { + // try to use int[] instead of long[] to reduce memory usage, and move to the sum array when overflow + private final AtomicReference<DecayingArray> decayingRef; + private final long[] estimated; + private volatile boolean writing; Review Comment: potential false sharing with the array reference.. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org