Skip to content

Commit

Permalink
[WIP] Compact MetricName tag map implementation (#1368)
Browse files Browse the repository at this point in the history
Compact MetricName tag map implementation
  • Loading branch information
carterkozak authored Mar 1, 2022
1 parent ba66c38 commit a120435
Show file tree
Hide file tree
Showing 9 changed files with 720 additions and 307 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1368.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Compact MetricName tag map implementation
links:
- https://github.com/palantir/tritium/pull/1368
2 changes: 1 addition & 1 deletion tritium-jmh/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks.jmhCompileGeneratedClasses {

dependencies {

annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
api 'io.dropwizard.metrics:metrics-core'

jmh project(':tritium-api')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.palantir.tritium.microbenchmarks;

import com.codahale.metrics.Meter;
import com.codahale.metrics.Metric;
import com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry;
import com.palantir.tritium.metrics.registry.MetricName;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -38,34 +40,39 @@
import org.openjdk.jmh.runner.options.OptionsBuilder;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
@State(Scope.Benchmark)
@SuppressWarnings({"designforextension", "NullAway"})
public class NestedMetricsBenchmark {
private TaggedMetricRegistry metrics;
private BiConsumer<MetricName, Metric> consumer;

@Setup
public void before() {
public void before(Blackhole blackhole) {
metrics = constructBaseRegistry();
consumer = (name, metric) -> {
blackhole.consume(name.safeName());
// name.safeTags().forEach(blackholeConsumer) would be ideal,
// however most readers will use the entrySet
for (Map.Entry<String, String> entry : name.safeTags().entrySet()) {
blackhole.consume(entry.getKey());
blackhole.consume(entry.getValue());
}
blackhole.consume(metric);
};
}

@Benchmark
public void benchmarkGetMetrics(Blackhole blackhole) {
metrics.getMetrics().forEach((name, metric) -> {
blackhole.consume(name);
blackhole.consume(metric);
});
public void benchmarkGetMetrics() {
metrics.getMetrics().forEach(consumer);
}

@Benchmark
public void benchmarkForEach(Blackhole blackhole) {
metrics.forEachMetric((name, metric) -> {
blackhole.consume(name);
blackhole.consume(metric);
});
public void benchmarkForEach() {
metrics.forEachMetric(consumer);
}

private static TaggedMetricRegistry constructBaseRegistry() {
Expand All @@ -79,13 +86,13 @@ private static TaggedMetricRegistry constructBaseRegistry() {
private static TaggedMetricRegistry constructSubRegistry() {
TaggedMetricRegistry registry = new DefaultTaggedMetricRegistry();
for (int i = 0; i < 100; i++) {
Meter meter = registry.meter(MetricName.builder()
.safeName("some metric " + i)
.putSafeTags("some tag", "some tag value")
.build());
for (int j = 0; j < 1000; j++) {
meter.mark();
}
registry.meter(MetricName.builder()
.safeName("some metric " + i)
.putSafeTags("some tag", "some tag value")
.putSafeTags("libraryName", "tritium")
.putSafeTags("libraryVersion", "1.2.3")
.build())
.mark();
}
return registry;
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit a120435

Please sign in to comment.