Skip to content

Commit

Permalink
Merge branch '1.14.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Dec 25, 2024
2 parents 9d650ca + b2d8277 commit e4028e9
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,26 @@
*/
@Fork(1)
@Measurement(iterations = 2)
@Warmup(iterations = 2)
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 3)
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Threads(16)
@Threads(2)
public class CompareOTLPHistograms {

// disable publishing since we are only benchmarking recording
static OtlpConfig disabledConfig = new OtlpConfig() {

@Override
public boolean enabled() {
return false;
}

@Override
public String get(String key) {
return "";
}
};

@State(Scope.Thread)
public static class Data {

Expand Down Expand Up @@ -82,7 +96,7 @@ public static class DistributionsWithoutHistogramCumulative {

@Setup(Level.Iteration)
public void setup() {
registry = new OtlpMeterRegistry();
registry = new OtlpMeterRegistry(disabledConfig, Clock.SYSTEM);
distributionSummary = DistributionSummary.builder("ds").register(registry);
timer = Timer.builder("timer").register(registry);
}
Expand All @@ -99,6 +113,11 @@ public static class DistributionsWithoutHistogramDelta {

OtlpConfig otlpConfig = new OtlpConfig() {

@Override
public boolean enabled() {
return false;
}

@Override
public AggregationTemporality aggregationTemporality() {
return AggregationTemporality.DELTA;
Expand Down Expand Up @@ -142,7 +161,7 @@ public static class ExplicitBucketHistogramCumulative {

@Setup(Level.Iteration)
public void setup() {
registry = new OtlpMeterRegistry();
registry = new OtlpMeterRegistry(disabledConfig, Clock.SYSTEM);
distributionSummary = DistributionSummary.builder("ds").publishPercentileHistogram().register(registry);
timer = Timer.builder("timer").publishPercentileHistogram().register(registry);
}
Expand All @@ -159,6 +178,11 @@ public static class ExplicitBucketHistogramDelta {

OtlpConfig otlpConfig = new OtlpConfig() {

@Override
public boolean enabled() {
return false;
}

@Override
public AggregationTemporality aggregationTemporality() {
return AggregationTemporality.DELTA;
Expand Down Expand Up @@ -197,6 +221,12 @@ public static class ExponentialHistogramCumulative {
MeterRegistry registry;

OtlpConfig otlpConfig = new OtlpConfig() {

@Override
public boolean enabled() {
return false;
}

@Override
public HistogramFlavor histogramFlavor() {
return HistogramFlavor.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM;
Expand Down Expand Up @@ -234,6 +264,11 @@ public static class ExponentialHistogramDelta {

OtlpConfig otlpConfig = new OtlpConfig() {

@Override
public boolean enabled() {
return false;
}

@Override
public AggregationTemporality aggregationTemporality() {
return AggregationTemporality.DELTA;
Expand Down
2 changes: 2 additions & 0 deletions concurrency-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies {
// implementation("io.micrometer:micrometer-core:1.14.1")
implementation project(":micrometer-registry-prometheus")
// implementation("io.micrometer:micrometer-registry-prometheus:1.14.1")
implementation project(":micrometer-registry-otlp")

runtimeOnly(libs.logbackLatest)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2024 VMware, Inc.
*
* Licensed 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
*
* https://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 io.micrometer.concurrencytests;

import static org.openjdk.jcstress.annotations.Expect.*;
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;
import static org.openjdk.jcstress.annotations.Expect.FORBIDDEN;

import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.*;
import io.micrometer.registry.otlp.internal.Base2ExponentialHistogram;
import io.micrometer.registry.otlp.internal.CumulativeBase2ExponentialHistogram;

public class Base2ExponentialHistogramConcurrencyTests {

@JCStressTest
@Outcome(id = "null, 5, 2", expect = ACCEPTABLE, desc = "Read after all writes")
@Outcome(id = "null, 20, 0", expect = ACCEPTABLE, desc = "Read before write")
@Outcome(id = { "null, 20, 1" }, expect = ACCEPTABLE, desc = "Reading after single " + "write")
@Outcome(
id = { "class java.lang.ArrayIndexOutOfBoundsException, 20, 0",
"class java.lang.ArrayIndexOutOfBoundsException, 20, 1" },
expect = FORBIDDEN, desc = "Exception in recording thread")
@Outcome(
id = "class java.lang.ArrayIndexOutOfBoundsException, class java.lang.ArrayIndexOutOfBoundsException, null",
expect = FORBIDDEN, desc = "Exception in both reading and writing threads")
@Outcome(id = "null, class java.lang.ArrayIndexOutOfBoundsException, null", expect = FORBIDDEN,
desc = "Exception in reading thread")
@Outcome(expect = UNKNOWN)
@State
public static class RescalingAndConcurrentReading {

Base2ExponentialHistogram exponentialHistogram = new CumulativeBase2ExponentialHistogram(20, 40, 0, null);

@Actor
public void actor1(LLL_Result r) {
try {
exponentialHistogram.recordDouble(2);
}
catch (Exception e) {
r.r1 = e.getClass();
}
}

@Actor
public void actor2(LLL_Result r) {
try {
exponentialHistogram.recordDouble(4);
}
catch (Exception e) {
r.r1 = e.getClass();
}
}

@Actor
public void actor3(LLL_Result r) {
try {
exponentialHistogram.takeSnapshot(2, 6, 4);
r.r2 = exponentialHistogram.getLatestExponentialHistogramSnapshot().scale();
r.r3 = exponentialHistogram.getLatestExponentialHistogramSnapshot()
.positive()
.bucketCounts()
.stream()
.mapToLong(Long::longValue)
.sum();
}
catch (Exception e) {
r.r2 = e.getClass();
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,16 @@ public void recordDouble(double value) {
zeroCount.increment();
return;
}
recordToHistogram(value);
}

private synchronized void recordToHistogram(final double value) {
int index = base2IndexProvider.getIndexForValue(value);
if (!circularCountHolder.increment(index, 1)) {
synchronized (this) {
int downScaleFactor = getDownScaleFactor(index);
downScale(downScaleFactor);
index = base2IndexProvider.getIndexForValue(value);
circularCountHolder.increment(index, 1);
}
int downScaleFactor = getDownScaleFactor(index);
downScale(downScaleFactor);
index = base2IndexProvider.getIndexForValue(value);
circularCountHolder.increment(index, 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.micrometer.registry.otlp.internal;

import java.util.concurrent.atomic.AtomicLongArray;
import java.util.Arrays;

/**
* The CircularCountHolder is inspired from <a href=
Expand All @@ -25,7 +25,7 @@
*/
class CircularCountHolder {

private final AtomicLongArray counts;
private final long[] counts;

private final int length;

Expand All @@ -37,7 +37,7 @@ class CircularCountHolder {

CircularCountHolder(int size) {
this.length = size;
this.counts = new AtomicLongArray(size);
this.counts = new long[size];
this.baseIndex = Integer.MIN_VALUE;
this.startIndex = Integer.MIN_VALUE;
this.endIndex = Integer.MIN_VALUE;
Expand All @@ -52,7 +52,7 @@ int getEndIndex() {
}

long getValueAtIndex(int index) {
return counts.get(getRelativeIndex(index));
return counts[getRelativeIndex(index)];
}

boolean isEmpty() {
Expand All @@ -64,7 +64,7 @@ boolean increment(int index, long incrementBy) {
this.baseIndex = index;
this.startIndex = index;
this.endIndex = index;
this.counts.addAndGet(0, incrementBy);
this.counts[0] = this.counts[0] + incrementBy;
return true;
}

Expand All @@ -81,7 +81,8 @@ else if (index < startIndex) {
startIndex = index;
}

counts.addAndGet(getRelativeIndex(index), incrementBy);
final int relativeIndex = getRelativeIndex(index);
counts[relativeIndex] = counts[relativeIndex] + incrementBy;
return true;
}

Expand All @@ -97,9 +98,7 @@ else if (result < 0) {
}

void reset() {
for (int i = 0; i < counts.length(); i++) {
counts.set(i, 0);
}
Arrays.fill(counts, 0);
this.baseIndex = Integer.MIN_VALUE;
this.endIndex = Integer.MIN_VALUE;
this.startIndex = Integer.MIN_VALUE;
Expand Down

0 comments on commit e4028e9

Please sign in to comment.