belliottsmith commented on code in PR #4324: URL: https://github.com/apache/cassandra/pull/4324#discussion_r2316133393
########## src/java/org/apache/cassandra/metrics/ThreadLocalMeter.java: ########## @@ -0,0 +1,372 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.metrics; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import com.google.common.annotations.VisibleForTesting; + +import com.codahale.metrics.Clock; +import org.apache.cassandra.concurrent.ScheduledExecutors; +import org.apache.cassandra.utils.MonotonicClock; +import org.apache.cassandra.utils.ReflectionUtils; + +import static java.lang.Math.exp; + +/** + * An alternative to Dropwizard Meter which implements the same kind of API. + * it has more efficent mark operations and consumes less memory. + * Only exponential decaying moving average is supported for 1/5/15-minutes rate values. + * Tick logic is moved out from a mark operation and always executed in a background thread. + * For better cache locality rate values are extracted to a common non thread-local array + * updated by a background thread in bulk. + * Counter logic inside is implemented using @see ThreadLocalMetrics functionality. + * NOTE: Dropwizard Meter is a class and there is no an interface for Dropwizard Meter logic, + * so we have to create an alternative hierarchy. + */ +public class ThreadLocalMeter extends com.codahale.metrics.Meter implements Meter Review Comment: I'm wondering whether we need to maintain all of the separate rate metrics at the thread level. Since we track the same 1m/5m/15m rates for every Meter, can't we just track the number of ticks in the last x seconds, and then as that rolls over propagate it to shared 1m/5m/15m roll-ups? I don't have a strong opinion here, I just have always felt it's a bit weird the effort we go to maintaining these rollups for every metric, simply because this is what Codahale defaults to. But, I also don't want to impose lots of extra work if you think the current design makes sense, as it's already a big improvement. For reference, I am about to merge a version of this for Accord that simply tracks 1m buckets for the past 16m; on read each minute is blended with the prior minute at a ratio based on the time that has elapsed since the last rollover. An approach like this could work, with only the most recent minute being tracked per-thread. -- 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]

