mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
structuring and naming changes
This commit is contained in:
@@ -14,9 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.scenarios.simframe.findmax;
|
||||
package io.nosqlbench.scenarios.simframe.findmax.planners;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.core.Activity;
|
||||
import io.nosqlbench.engine.api.activityapi.ratelimits.simrate.CycleRateSpec;
|
||||
import io.nosqlbench.engine.api.activityapi.ratelimits.simrate.SimRateSpec;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
|
||||
import io.nosqlbench.nb.api.components.events.ParamChange;
|
||||
import io.nosqlbench.scenarios.simframe.capture.JournalView;
|
||||
import io.nosqlbench.scenarios.simframe.findmax.FindMaxFrameParams;
|
||||
import io.nosqlbench.scenarios.simframe.findmax.FindmaxSearchParams;
|
||||
import io.nosqlbench.scenarios.simframe.planning.SimFrame;
|
||||
import io.nosqlbench.scenarios.simframe.planning.SimFramePlanner;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -24,11 +31,16 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class FindMaxPlanner extends SimFramePlanner<FindmaxSearchParams, FindMaxFrameParams> {
|
||||
private final Logger logger = LogManager.getLogger(FindMaxPlanner.class);
|
||||
public class FindmaxRampup extends SimFramePlanner<FindmaxSearchParams, FindMaxFrameParams> {
|
||||
private final Logger logger = LogManager.getLogger(FindmaxRampup.class);
|
||||
|
||||
public FindMaxPlanner(FindmaxSearchParams findMaxSettings) {
|
||||
super(findMaxSettings);
|
||||
public FindmaxRampup(NBCommandParams analyzerParams) {
|
||||
super(analyzerParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FindmaxSearchParams getConfig(NBCommandParams params) {
|
||||
return new FindmaxSearchParams(params);
|
||||
}
|
||||
|
||||
public FindMaxFrameParams initialStep() {
|
||||
@@ -44,11 +56,12 @@ public class FindMaxPlanner extends SimFramePlanner<FindmaxSearchParams, FindMax
|
||||
*
|
||||
* @param journal
|
||||
* All parameters and results, organized in enumerated simulation frames
|
||||
* @return Optionally, a set of params which indicates another simulation frame should be sampled, else null
|
||||
* @return Optionally, a set of paramValues which indicates another simulation frame should be sampled, else null
|
||||
*/
|
||||
public FindMaxFrameParams nextStep(JournalView journal) {
|
||||
SimFrame last = journal.last();
|
||||
SimFrame best = journal.bestRun();
|
||||
@Override
|
||||
public FindMaxFrameParams nextStep(JournalView<FindMaxFrameParams> journal) {
|
||||
SimFrame<FindMaxFrameParams> last = journal.last();
|
||||
SimFrame<FindMaxFrameParams> best = journal.bestRun();
|
||||
if (best.index() == last.index()) { // got better consecutively
|
||||
return new FindMaxFrameParams(
|
||||
last.params().rate_shelf(),
|
||||
@@ -73,7 +86,7 @@ public class FindMaxPlanner extends SimFramePlanner<FindmaxSearchParams, FindMax
|
||||
}
|
||||
} else { // any other case
|
||||
// find next frame with higher rate but lower value, the closest one by rate
|
||||
SimFrame nextWorseFrameWithHigherRate = journal.frames().stream()
|
||||
SimFrame<FindMaxFrameParams> nextWorseFrameWithHigherRate = journal.frames().stream()
|
||||
.filter(f -> f.value() < best.value())
|
||||
.filter(f -> f.params().computed_rate() > best.params().computed_rate())
|
||||
.min(Comparator.comparingDouble(f -> f.params().computed_rate()))
|
||||
@@ -93,4 +106,10 @@ public class FindMaxPlanner extends SimFramePlanner<FindmaxSearchParams, FindMax
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyParams(FindMaxFrameParams params, Activity flywheel) {
|
||||
flywheel.onEvent(ParamChange.of(new CycleRateSpec(params.rate_shelf()+params.rate_delta(), 1.1d, SimRateSpec.Verb.restart)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.scenarios.simframe.optimo;
|
||||
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBBaseCommand;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBCommandInfo;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
@Service(value = NBCommandInfo.class,selector = "optimo")
|
||||
public class NBOptimoInfo extends NBCommandInfo {
|
||||
@Override
|
||||
public Class<? extends NBBaseCommand> getType() {
|
||||
return NB_optimo.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.scenarios.simframe.optimo;
|
||||
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OptimoFrameParams{
|
||||
|
||||
OptimoParamModel model;
|
||||
double[] paramValues;
|
||||
|
||||
public OptimoFrameParams(OptimoParamModel model, double[] paramValues) {
|
||||
this.model = model;
|
||||
this.paramValues = paramValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return model.summarizeParams(paramValues);
|
||||
}
|
||||
|
||||
public double[] paramValues() {
|
||||
return paramValues;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.scenarios.simframe.optimo;
|
||||
|
||||
public class ThreadSpec {
|
||||
public ThreadSpec(double threads) {
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.scenarios.simframe.stats;
|
||||
package io.nosqlbench.scenarios.simframe.stabilization;
|
||||
|
||||
public class DoubleRing {
|
||||
private final double[] dbuf;
|
||||
@@ -14,12 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.scenarios.simframe.stats;
|
||||
package io.nosqlbench.scenarios.simframe.stabilization;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.function.DoubleSupplier;
|
||||
|
||||
public class StabilityDetector implements Runnable {
|
||||
@@ -30,6 +32,9 @@ public class StabilityDetector implements Runnable {
|
||||
private StatBucket[] buckets;
|
||||
private int[] windows;
|
||||
private volatile boolean running = true;
|
||||
private long startedAt;
|
||||
private long nextCheckAt;
|
||||
private double detectionTime;
|
||||
|
||||
/**
|
||||
* Configure a stability checker that reads values from a source on some timed loop,
|
||||
@@ -65,17 +70,18 @@ public class StabilityDetector implements Runnable {
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
detectionTime = -1L;
|
||||
this.buckets = new StatBucket[windows.length];
|
||||
for (int i = 0; i < windows.length; i++) {
|
||||
buckets[i] = new StatBucket(windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public double apply(double value) {
|
||||
public void apply(double value) {
|
||||
for (StatBucket bucket : buckets) {
|
||||
bucket.apply(value);
|
||||
}
|
||||
return computeStability();
|
||||
// return computeStability();
|
||||
}
|
||||
|
||||
private boolean primed() {
|
||||
@@ -87,7 +93,9 @@ public class StabilityDetector implements Runnable {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private double computeStability() {
|
||||
// System.out.println("priming " + this.buckets[0].count() + "/" + this.buckets[0].ringbuf.size());
|
||||
if (!primed()) {
|
||||
return -1.0d;
|
||||
}
|
||||
@@ -98,17 +106,24 @@ public class StabilityDetector implements Runnable {
|
||||
double basis = 1.0d;
|
||||
|
||||
for (int i = 0; i < buckets.length - 1; i++) {
|
||||
double reductionFactor = stddev[i] / stddev[i + 1];
|
||||
// if previous bigger window had a higher stddev than the one after, then it is converging
|
||||
double reductionFactor = (stddev[i + 1] / stddev[i]);
|
||||
basis *= reductionFactor;
|
||||
}
|
||||
System.out.printf("STABILITY %g :", basis);
|
||||
for (int i = 0; i < stddev.length; i++) {
|
||||
System.out.printf("[%d]: %g ", windows[i], stddev[i]);
|
||||
|
||||
// TODO: investigate why we get NaN sometimes and what it means for stability checks
|
||||
// TODO: turn this into a one line summary with some cool unicode characters
|
||||
double time = ((double)(nextCheckAt - startedAt))/1000d;
|
||||
|
||||
|
||||
if (time>10.0) {
|
||||
System.out.print(stabilitySummary(stddev));
|
||||
System.out.printf("% 4.1fS STABILITY %g :", time, basis);
|
||||
for (int i = 0; i < stddev.length; i++) {
|
||||
System.out.printf("[%d]: %g ", windows[i], stddev[i]);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println();
|
||||
// logger.info("STABILITY " + basis);
|
||||
|
||||
|
||||
return basis;
|
||||
|
||||
}
|
||||
@@ -118,14 +133,13 @@ public class StabilityDetector implements Runnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
int interval = (int) this.timeSliceSeconds / 1000;
|
||||
int interval = (int) (this.timeSliceSeconds * 1000);
|
||||
startedAt = System.currentTimeMillis();
|
||||
reset();
|
||||
|
||||
boolean steadyEnough = false;
|
||||
long lastCheck = System.currentTimeMillis();
|
||||
long nextCheckAt = lastCheck + interval;
|
||||
nextCheckAt = startedAt + interval;
|
||||
|
||||
while (running && !steadyEnough) {
|
||||
while (running) {
|
||||
long delay = nextCheckAt - System.currentTimeMillis();
|
||||
while (delay > 0) {
|
||||
try {
|
||||
@@ -134,14 +148,45 @@ public class StabilityDetector implements Runnable {
|
||||
}
|
||||
delay = nextCheckAt - System.currentTimeMillis();
|
||||
}
|
||||
|
||||
double value = source.getAsDouble();
|
||||
apply(value);
|
||||
double stabilityFactor = computeStability();
|
||||
// if (Double.isNaN(stabilityFactor)) {
|
||||
// System.out.println("NaN stability factor");
|
||||
// }
|
||||
|
||||
if (stabilityFactor > threshold) {
|
||||
detectionTime = ((double) (nextCheckAt - startedAt)) / 1000d;
|
||||
return;
|
||||
}
|
||||
nextCheckAt += interval;
|
||||
}
|
||||
}
|
||||
|
||||
private static String levels8 = " ▁▂▃▄▅▆▇";
|
||||
public String stabilitySummary(double[] stddev) {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
double bias=(1.0d/16.0);
|
||||
double max=0.0d;
|
||||
for (int i = 0; i < stddev.length; i++) {
|
||||
max=Math.max(max,stddev[i]);
|
||||
}
|
||||
for (int i = 0; i < stddev.length; i++) {
|
||||
int idx = Math.min(7,((int)(stddev[i]/max)*levels8.length()));
|
||||
char c = levels8.charAt(idx);
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append("] ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (detectionTime > 0L) {
|
||||
return String.format("results converged in % 4.2fS", detectionTime);
|
||||
} else {
|
||||
return String.format("awaiting convergence for % 4.2fS", (((double) (nextCheckAt - startedAt)) / 1000d));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.scenarios.simframe.stats;
|
||||
package io.nosqlbench.scenarios.simframe.stabilization;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.scenarios.simframe.stats;
|
||||
package io.nosqlbench.scenarios.simframe.stabilization;
|
||||
|
||||
public record TimedSample(long msTime, double value) {
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.scenarios.simframe.stats;
|
||||
package io.nosqlbench.scenarios.simframe.stabilization;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
Reference in New Issue
Block a user