Skip to content

Commit

Permalink
Rebased ScopeImpl to use CopyOnWriteArrayList instead of `Concurr…
Browse files Browse the repository at this point in the history
…entLinkedQueue`, to avoid read path peanlty of the CLQ, since reporting list is "write once, read many" use-case
  • Loading branch information
Alexey Kudinkin committed Aug 10, 2021
1 parent d6580ca commit c73ad2b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/com/uber/m3/tally/ScopeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;

/**
Expand All @@ -49,7 +49,7 @@ class ScopeImpl implements Scope {
private final ConcurrentHashMap<String, GaugeImpl> gauges = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, HistogramImpl> histograms = new ConcurrentHashMap<>();

private final ConcurrentLinkedQueue<Reportable> reportingQueue = new ConcurrentLinkedQueue<>();
private final CopyOnWriteArrayList<Reportable> reportingList = new CopyOnWriteArrayList<>();

private final ConcurrentHashMap<String, TimerImpl> timers = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -137,15 +137,15 @@ public void close() {
}

<T extends Reportable> void addToReportingQueue(T metric) {
reportingQueue.add(metric);
reportingList.add(metric);
}

/**
* Reports using the specified reporter.
* @param reporter the reporter to report
*/
void report(StatsReporter reporter) {
for (Reportable metric : reportingQueue) {
for (Reportable metric : reportingList) {
metric.report(tags, reporter);
}
}
Expand Down

0 comments on commit c73ad2b

Please sign in to comment.