Skip to content

Commit

Permalink
Move JLBH classes from core package, closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
glukos committed Jun 7, 2021
1 parent 9d43235 commit 3da1f6a
Show file tree
Hide file tree
Showing 32 changed files with 1,336 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ http://www.rationaljava.com/2016/04/jlbh-examples-4-benchmarking-quickfix.html[B

=== Using JLBH as part of automated performance/performance regression testing

The net.openhft.chronicle.core.jlbh.JLBHTest::shouldProvideResultData
The net.openhft.chronicle.jlbh.JLBHTest::shouldProvideResultData
test shows how the latency percentiles can be extracted
and used in the xUnit type of testing frameworks. Ideally, such tests should be run in the environment
identical to the production one - it can be achieved by having a special, production-like CI server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static java.util.Collections.unmodifiableMap;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
class ImmutableJLBHResult implements JLBHResult {

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
class ImmutableProbeResult implements JLBHResult.ProbeResult {

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static java.util.Collections.unmodifiableMap;
import static net.openhft.chronicle.core.jlbh.JLBHResult.RunResult.Percentile.*;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
class ImmutableRunResult implements JLBHResult.RunResult {

private final Map<Percentile, Duration> percentiles;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/openhft/chronicle/core/jlbh/JLBH.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* This tool was inspired by JMH.
*/
@SuppressWarnings("unused")
@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public class JLBH implements NanoSampler {
private static final Double[] NO_DOUBLES = {};
private final SortedMap<String, Histogram> additionHistograms = new ConcurrentSkipListMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
/**
* Data structure to store the options to pass into the JLBH constructor
*/
@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public class JLBHOptions {
int throughput = 10_000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Optional;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public interface JLBHResult {

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public interface JLBHResultConsumer extends Consumer<JLBHResult>, Supplier<JLBHResult> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* Interface for tasks using the JLBH framework.
*/
@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public interface JLBHTask {
/**
* This method is called before the benchmark is started.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.openhft.chronicle.core.jlbh;

@FunctionalInterface
@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public interface LatencyDistributor {
long apply(long averageLatencyNS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.concurrent.ThreadLocalRandom;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public enum LatencyDistributors implements LatencyDistributor {
NORMAL {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Map;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
public class TeamCityHelper {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package net.openhft.chronicle.core.jlbh;

@Deprecated(/* moved from net.openhft.chronicle.core.jlbh to net.openhft.chronicle.jlbh */)
final class ThreadSafeJLBHResultConsumer implements JLBHResultConsumer {

// the assumption is that the JLBHResult is immutable
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/net/openhft/chronicle/jlbh/ImmutableJLBHResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2016-2020 chronicle.software
*
* https://chronicle.software
*
* 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
*
* 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 net.openhft.chronicle.jlbh;

import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Optional;

import static java.util.Collections.unmodifiableMap;

class ImmutableJLBHResult implements JLBHResult {

@NotNull
private final ProbeResult endToEndProbeResult;
@NotNull
private final Map<String, ProbeResult> additionalProbeResults;

ImmutableJLBHResult(@NotNull ProbeResult endToEndProbeResult, @NotNull Map<String, ? extends ProbeResult> additionalProbeResults) {
this.endToEndProbeResult = endToEndProbeResult;
this.additionalProbeResults = unmodifiableMap(additionalProbeResults);
}

@Override
@NotNull
public ProbeResult endToEnd() {
return endToEndProbeResult;
}

@Override
@NotNull
public Optional<ProbeResult> probe(String probeName) {
return Optional.ofNullable(additionalProbeResults.get(probeName));
}
}
48 changes: 48 additions & 0 deletions src/main/java/net/openhft/chronicle/jlbh/ImmutableProbeResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2016-2020 chronicle.software
*
* https://chronicle.software
*
* 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
*
* 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 net.openhft.chronicle.jlbh;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;

class ImmutableProbeResult implements JLBHResult.ProbeResult {

@NotNull
private final List<JLBHResult.RunResult> runsSummary;

public ImmutableProbeResult(List<double[]> percentileRuns) {
runsSummary = unmodifiableList(percentileRuns.stream().map(ImmutableRunResult::new).collect(toList()));
}

@NotNull
@Override
public JLBHResult.RunResult summaryOfLastRun() {
return runsSummary.get(runsSummary.size() - 1);
}

@NotNull
@Override
public List<JLBHResult.RunResult> eachRunSummary() {
return runsSummary;
}
}
130 changes: 130 additions & 0 deletions src/main/java/net/openhft/chronicle/jlbh/ImmutableRunResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright 2016-2020 chronicle.software
*
* https://chronicle.software
*
* 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
*
* 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 net.openhft.chronicle.jlbh;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.Duration;
import java.util.EnumMap;
import java.util.Map;

import static java.time.temporal.ChronoUnit.NANOS;
import static java.util.Collections.unmodifiableMap;
import static net.openhft.chronicle.jlbh.JLBHResult.RunResult.Percentile.*;

class ImmutableRunResult implements JLBHResult.RunResult {

private final Map<Percentile, Duration> percentiles;

public ImmutableRunResult(double[] percentiles) {
this.percentiles = asMap(percentiles);
}

private static Map<Percentile, Duration> asMap(double[] percentiles) {
final Map<Percentile, Duration> data = new EnumMap<>(Percentile.class);
// TODO: duplicate of knowledge with Histogram.percentilesFor()
data.put(PERCENTILE_50TH, durationOf(percentiles[0]));
data.put(PERCENTILE_90TH, durationOf(percentiles[1]));
data.put(PERCENTILE_99TH, durationOf(percentiles[2]));
if (percentiles.length > 4) {
data.put(PERCENTILE_99_7TH, durationOf(percentiles[3]));
}
if (percentiles.length > 5) {
data.put(PERCENTILE_99_9TH, durationOf(percentiles[4]));
}
if (percentiles.length > 6) {
data.put(PERCENTILE_99_97TH, durationOf(percentiles[5]));
}
if (percentiles.length > 7) {
data.put(PERCENTILE_99_99TH, durationOf(percentiles[6]));
}
data.put(WORST, durationOf(percentiles[percentiles.length - 1]));
return unmodifiableMap(data);
}

private static Duration durationOf(double percentile) {
return Duration.of((long) percentile, NANOS);
}

@Override
@NotNull
public Map<Percentile, Duration> percentiles() {
return percentiles;
}

@Override
@NotNull
public Duration get50thPercentile() {
return percentiles.get(PERCENTILE_50TH);
}

@Override
@NotNull
public Duration get90thPercentile() {
return percentiles.get(PERCENTILE_90TH);
}

@Override
@NotNull
public Duration get99thPercentile() {
return percentiles.get(PERCENTILE_99TH);
}

@Override
@Nullable
public Duration get999thPercentile() {
return percentiles.get(PERCENTILE_99_9TH);
}

@Override
@Nullable
public Duration get9999thPercentile() {
return percentiles.get(PERCENTILE_99_99TH);
}

@Override
@NotNull
public Duration getWorst() {
return percentiles.get(WORST);
}

@Override
public String toString() {
return "ImmutableRunResult{" +
"percentiles=" + percentiles +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ImmutableRunResult summary = (ImmutableRunResult) o;

return percentiles.equals(summary.percentiles);

}

@Override
public int hashCode() {
return percentiles.hashCode();
}
}
Loading

0 comments on commit 3da1f6a

Please sign in to comment.