Skip to content

Commit

Permalink
reformat all files with spotless (#1015)
Browse files Browse the repository at this point in the history
* reformat all files with spotless

Signed-off-by: Gregor Zeitlinger <[email protected]>

* reformat all files with spotless

Signed-off-by: Gregor Zeitlinger <[email protected]>

---------

Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger authored Oct 1, 2024
1 parent 50d9950 commit 397738e
Show file tree
Hide file tree
Showing 220 changed files with 23,898 additions and 22,085 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v4
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.prometheus.metrics.benchmarks;

public class BenchmarkRunner {
public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}
public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Results on a machine with dedicated 8 vCPU cores:
*
* <pre>
* Benchmark Mode Cnt Score Error Units
* i.p.metrics.benchmarks.CounterBenchmark.codahaleIncNoLabels thrpt 25 30978.055 ± 424.088 ops/s
Expand All @@ -32,182 +33,174 @@
* i.p.metrics.benchmarks.CounterBenchmark.simpleclientInc thrpt 25 9057.637 ± 67.761 ops/s
* i.p.metrics.benchmarks.CounterBenchmark.simpleclientNoLabelsInc thrpt 25 8993.471 ± 49.581 ops/s
* </pre>
* Prometheus counters are faster than counters of other libraries. For example, incrementing a single counter
* without labels is more than 2 times faster (34752 ops / second) than doing the same with an OpenTelemetry
* counter (16634 ops / sec).
*
* Prometheus counters are faster than counters of other libraries. For example, incrementing a
* single counter without labels is more than 2 times faster (34752 ops / second) than doing the
* same with an OpenTelemetry counter (16634 ops / sec).
*/
public class CounterBenchmark {

@State(Scope.Benchmark)
public static class PrometheusCounter {

final Counter noLabels;
final CounterDataPoint dataPoint;

public PrometheusCounter() {
noLabels = Counter.builder()
.name("test")
.help("help")
.build();

Counter labels = Counter.builder()
.name("test")
.help("help")
.labelNames("path", "status")
.build();
this.dataPoint = labels.labelValues("/", "200");
}
}
@State(Scope.Benchmark)
public static class PrometheusCounter {

@State(Scope.Benchmark)
public static class SimpleclientCounter {
final Counter noLabels;
final CounterDataPoint dataPoint;

final io.prometheus.client.Counter noLabels;
final io.prometheus.client.Counter.Child dataPoint;
public PrometheusCounter() {
noLabels = Counter.builder().name("test").help("help").build();

public SimpleclientCounter() {
noLabels = io.prometheus.client.Counter.build()
.name("name")
.help("help")
.create();
Counter labels =
Counter.builder().name("test").help("help").labelNames("path", "status").build();
this.dataPoint = labels.labelValues("/", "200");
}
}

io.prometheus.client.Counter counter = io.prometheus.client.Counter.build()
.name("name")
.help("help")
.labelNames("path", "status")
.create();
@State(Scope.Benchmark)
public static class SimpleclientCounter {

this.dataPoint = counter.labels("/", "200");
}
}
final io.prometheus.client.Counter noLabels;
final io.prometheus.client.Counter.Child dataPoint;

@State(Scope.Benchmark)
public static class CodahaleCounterNoLabels {
final com.codahale.metrics.Counter counter = new com.codahale.metrics.MetricRegistry().counter("test");
}
public SimpleclientCounter() {
noLabels = io.prometheus.client.Counter.build().name("name").help("help").create();

@State(Scope.Benchmark)
public static class OpenTelemetryCounter {

final LongCounter longCounter;
final DoubleCounter doubleCounter;
final Attributes attributes;

public OpenTelemetryCounter() {

SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
.registerMetricReader(InMemoryMetricReader.create())
.setResource(Resource.getDefault())
.build();
OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
.setMeterProvider(sdkMeterProvider)
.build();
Meter meter = openTelemetry
.meterBuilder("instrumentation-library-name")
.setInstrumentationVersion("1.0.0")
.build();
this.longCounter = meter
.counterBuilder("test1")
.setDescription("test")
.build();
this.doubleCounter = meter
.counterBuilder("test2")
.ofDoubles()
.setDescription("test")
.build();
this.attributes = Attributes.of(
AttributeKey.stringKey("path"), "/",
AttributeKey.stringKey("status"), "200");
}
}
io.prometheus.client.Counter counter =
io.prometheus.client.Counter.build()
.name("name")
.help("help")
.labelNames("path", "status")
.create();

@Benchmark
@Threads(4)
public CounterDataPoint prometheusAdd(RandomNumbers randomNumbers, PrometheusCounter counter) {
for (int i=0; i<randomNumbers.randomNumbers.length; i++) {
counter.dataPoint.inc(randomNumbers.randomNumbers[i]);
}
return counter.dataPoint;
this.dataPoint = counter.labels("/", "200");
}

@Benchmark
@Threads(4)
public CounterDataPoint prometheusInc(PrometheusCounter counter) {
for (int i=0; i<10*1024; i++) {
counter.dataPoint.inc();
}
return counter.dataPoint;
}

@State(Scope.Benchmark)
public static class CodahaleCounterNoLabels {
final com.codahale.metrics.Counter counter =
new com.codahale.metrics.MetricRegistry().counter("test");
}

@State(Scope.Benchmark)
public static class OpenTelemetryCounter {

final LongCounter longCounter;
final DoubleCounter doubleCounter;
final Attributes attributes;

public OpenTelemetryCounter() {

SdkMeterProvider sdkMeterProvider =
SdkMeterProvider.builder()
.registerMetricReader(InMemoryMetricReader.create())
.setResource(Resource.getDefault())
.build();
OpenTelemetry openTelemetry =
OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProvider).build();
Meter meter =
openTelemetry
.meterBuilder("instrumentation-library-name")
.setInstrumentationVersion("1.0.0")
.build();
this.longCounter = meter.counterBuilder("test1").setDescription("test").build();
this.doubleCounter = meter.counterBuilder("test2").ofDoubles().setDescription("test").build();
this.attributes =
Attributes.of(
AttributeKey.stringKey("path"), "/",
AttributeKey.stringKey("status"), "200");
}
}

@Benchmark
@Threads(4)
public DoubleCounter openTelemetryAdd(RandomNumbers randomNumbers, OpenTelemetryCounter counter) {
for (int i=0; i<randomNumbers.randomNumbers.length; i++) {
counter.doubleCounter.add(randomNumbers.randomNumbers[i], counter.attributes);
}
return counter.doubleCounter;
@Benchmark
@Threads(4)
public CounterDataPoint prometheusAdd(RandomNumbers randomNumbers, PrometheusCounter counter) {
for (int i = 0; i < randomNumbers.randomNumbers.length; i++) {
counter.dataPoint.inc(randomNumbers.randomNumbers[i]);
}

@Benchmark
@Threads(4)
public LongCounter openTelemetryInc(OpenTelemetryCounter counter) {
for (int i=0; i<10*1024; i++) {
counter.longCounter.add(1, counter.attributes);
}
return counter.longCounter;
return counter.dataPoint;
}

@Benchmark
@Threads(4)
public CounterDataPoint prometheusInc(PrometheusCounter counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.dataPoint.inc();
}

@Benchmark
@Threads(4)
public LongCounter openTelemetryIncNoLabels(OpenTelemetryCounter counter) {
for (int i=0; i<10*1024; i++) {
counter.longCounter.add(1);
}
return counter.longCounter;
return counter.dataPoint;
}

@Benchmark
@Threads(4)
public DoubleCounter openTelemetryAdd(RandomNumbers randomNumbers, OpenTelemetryCounter counter) {
for (int i = 0; i < randomNumbers.randomNumbers.length; i++) {
counter.doubleCounter.add(randomNumbers.randomNumbers[i], counter.attributes);
}

@Benchmark
@Threads(4)
public io.prometheus.client.Counter.Child simpleclientAdd(RandomNumbers randomNumbers, SimpleclientCounter counter) {
for (int i=0; i<randomNumbers.randomNumbers.length; i++) {
counter.dataPoint.inc(randomNumbers.randomNumbers[i]);
}
return counter.dataPoint;
return counter.doubleCounter;
}

@Benchmark
@Threads(4)
public LongCounter openTelemetryInc(OpenTelemetryCounter counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.longCounter.add(1, counter.attributes);
}

@Benchmark
@Threads(4)
public io.prometheus.client.Counter.Child simpleclientInc(SimpleclientCounter counter) {
for (int i=0; i<10*1024; i++) {
counter.dataPoint.inc();
}
return counter.dataPoint;
return counter.longCounter;
}

@Benchmark
@Threads(4)
public LongCounter openTelemetryIncNoLabels(OpenTelemetryCounter counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.longCounter.add(1);
}

@Benchmark
@Threads(4)
public com.codahale.metrics.Counter codahaleIncNoLabels(RandomNumbers randomNumbers, CodahaleCounterNoLabels counter) {
for (int i=0; i<10*1024; i++) {
counter.counter.inc();
}
return counter.counter;
return counter.longCounter;
}

@Benchmark
@Threads(4)
public io.prometheus.client.Counter.Child simpleclientAdd(
RandomNumbers randomNumbers, SimpleclientCounter counter) {
for (int i = 0; i < randomNumbers.randomNumbers.length; i++) {
counter.dataPoint.inc(randomNumbers.randomNumbers[i]);
}

@Benchmark
@Threads(4)
public io.prometheus.metrics.core.metrics.Counter prometheusNoLabelsInc(PrometheusCounter counter) {
for (int i=0; i<10*1024; i++) {
counter.noLabels.inc();
}
return counter.noLabels;
return counter.dataPoint;
}

@Benchmark
@Threads(4)
public io.prometheus.client.Counter.Child simpleclientInc(SimpleclientCounter counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.dataPoint.inc();
}

@Benchmark
@Threads(4)
public io.prometheus.client.Counter simpleclientNoLabelsInc(SimpleclientCounter counter) {
for (int i=0; i<10*1024; i++) {
counter.noLabels.inc();
}
return counter.noLabels;
return counter.dataPoint;
}

@Benchmark
@Threads(4)
public com.codahale.metrics.Counter codahaleIncNoLabels(
RandomNumbers randomNumbers, CodahaleCounterNoLabels counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.counter.inc();
}
return counter.counter;
}

@Benchmark
@Threads(4)
public io.prometheus.metrics.core.metrics.Counter prometheusNoLabelsInc(
PrometheusCounter counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.noLabels.inc();
}
return counter.noLabels;
}

@Benchmark
@Threads(4)
public io.prometheus.client.Counter simpleclientNoLabelsInc(SimpleclientCounter counter) {
for (int i = 0; i < 10 * 1024; i++) {
counter.noLabels.inc();
}
return counter.noLabels;
}
}
Loading

0 comments on commit 397738e

Please sign in to comment.