mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
converted config to a record type and changed frame step results to something more lucid
This commit is contained in:
committed by
Jonathan Shook
parent
7d961cb351
commit
7edf6fb85c
@@ -57,7 +57,7 @@ public class CMD_findmax extends NBBaseCommand {
|
|||||||
|
|
||||||
FindmaxConfig findmaxConfig = new FindmaxConfig(params);
|
FindmaxConfig findmaxConfig = new FindmaxConfig(params);
|
||||||
switch(findmaxConfig.optimization_type()) {
|
switch(findmaxConfig.optimization_type()) {
|
||||||
case "rate":
|
case "rate" ->
|
||||||
model.add("rate",
|
model.add("rate",
|
||||||
findmaxConfig.min_value(), // min
|
findmaxConfig.min_value(), // min
|
||||||
findmaxConfig.base_value(), // initial
|
findmaxConfig.base_value(), // initial
|
||||||
@@ -67,16 +67,14 @@ public class CMD_findmax extends NBBaseCommand {
|
|||||||
1.1d,
|
1.1d,
|
||||||
SimRateSpec.Verb.restart)))
|
SimRateSpec.Verb.restart)))
|
||||||
);
|
);
|
||||||
break;
|
case "threads" ->
|
||||||
case "threads":
|
|
||||||
model.add("threads",
|
model.add("threads",
|
||||||
findmaxConfig.min_value(), // min
|
findmaxConfig.min_value(), // min
|
||||||
findmaxConfig.base_value(), // initial
|
findmaxConfig.base_value(), // initial
|
||||||
findmaxConfig.max_value(), // max
|
findmaxConfig.max_value(), // max
|
||||||
threads -> flywheel.onEvent(ParamChange.of(new SetThreads((int) (threads))))
|
threads -> flywheel.onEvent(ParamChange.of(new SetThreads((int) (threads))))
|
||||||
);
|
);
|
||||||
break;
|
default ->
|
||||||
default:
|
|
||||||
throw new RuntimeException("Unsupported optimization type: " + findmaxConfig.optimization_type());
|
throw new RuntimeException("Unsupported optimization type: " + findmaxConfig.optimization_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package io.nosqlbench.scenarios.simframe.optimizers.findmax;
|
package io.nosqlbench.scenarios.simframe.optimizers.findmax;
|
||||||
|
|
||||||
import io.nosqlbench.scenarios.simframe.planning.SimFrame;
|
import io.nosqlbench.scenarios.simframe.planning.SimFrame;
|
||||||
|
import io.nosqlbench.scenarios.simframe.planning.SimFrameAction;
|
||||||
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunctionAnalyzer;
|
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunctionAnalyzer;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -31,23 +32,44 @@ public class FindmaxAnalyzer extends SimFrameFunctionAnalyzer<FindmaxFrameFuncti
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double nextFrame() {
|
protected FrameResult nextFrame() {
|
||||||
double newValue;
|
double newValue;
|
||||||
SimFrame<FindmaxFrameParams> last = function.getJournal().last();
|
SimFrame<FindmaxFrameParams> last = function.getJournal().last();
|
||||||
SimFrame<FindmaxFrameParams> best = function.getJournal().bestRun();
|
SimFrame<FindmaxFrameParams> best = function.getJournal().bestRun();
|
||||||
if (best.index() == last.index()) { // got better consecutively
|
if (best.index() == last.index()) { // got better consecutively
|
||||||
newValue = last.params().paramValues()[0] + config.step_value();
|
newValue = last.params().paramValues()[0] + config.step_value();
|
||||||
config.setStep_value(config.step_value() * config.value_incr());
|
config = new FindmaxConfig(
|
||||||
|
config.sample_time_ms(),
|
||||||
|
config.max_value(),
|
||||||
|
config.base_value(),
|
||||||
|
config.min_value(),
|
||||||
|
(config.step_value() * config.value_incr()),
|
||||||
|
config.value_incr(),
|
||||||
|
config.sample_incr(),
|
||||||
|
config.min_settling_ms(),
|
||||||
|
config.optimization_type(),
|
||||||
|
new double[]{newValue}
|
||||||
|
);
|
||||||
} else if (best.index() == last.index() - 1) {
|
} else if (best.index() == last.index() - 1) {
|
||||||
// got worse consecutively, this may be collapsed out since the general case below covers it (test first)
|
// got worse consecutively, this may be collapsed out since the general case below covers it (test first)
|
||||||
if (((last.params().paramValues()[0] + config.step_value()) -
|
if (((last.params().paramValues()[0] + config.step_value()) -
|
||||||
(best.params().paramValues()[0] + config.step_value())) <= config.step_value()) {
|
(best.params().paramValues()[0] + config.step_value())) <= config.step_value()) {
|
||||||
logger.info("could not divide search space further, stop condition met");
|
logger.info("could not divide search space further, stop condition met");
|
||||||
return Double.MIN_VALUE;
|
return new FrameResult(best.params().paramValues()[0], SimFrameAction.stop_run);
|
||||||
} else {
|
} else {
|
||||||
newValue = best.params().paramValues()[0] + config.step_value();
|
newValue = best.params().paramValues()[0] + config.step_value();
|
||||||
config.setSample_time_ms(config.sample_time_ms() * config.sample_incr());
|
config = new FindmaxConfig(
|
||||||
config.setMin_settling_ms(config.min_settling_ms() * 4);
|
(config.sample_time_ms() * config.sample_incr()),
|
||||||
|
config.max_value(),
|
||||||
|
config.base_value(),
|
||||||
|
config.min_value(),
|
||||||
|
config.step_value(),
|
||||||
|
config.value_incr(),
|
||||||
|
config.sample_incr(),
|
||||||
|
(config.min_settling_ms() * 4),
|
||||||
|
config.optimization_type(),
|
||||||
|
new double[]{newValue}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else { // any other case
|
} else { // any other case
|
||||||
// find next frame with higher rate but lower value, the closest one by rate
|
// find next frame with higher rate but lower value, the closest one by rate
|
||||||
@@ -59,14 +81,30 @@ public class FindmaxAnalyzer extends SimFrameFunctionAnalyzer<FindmaxFrameFuncti
|
|||||||
if ((nextWorseFrameWithHigherRate.params().paramValues()[0] + config.step_value() -
|
if ((nextWorseFrameWithHigherRate.params().paramValues()[0] + config.step_value() -
|
||||||
best.params().paramValues()[0] + config.step_value()) > config.step_value()) {
|
best.params().paramValues()[0] + config.step_value()) > config.step_value()) {
|
||||||
newValue = best.params().paramValues()[0] + config.step_value();
|
newValue = best.params().paramValues()[0] + config.step_value();
|
||||||
config.setSample_time_ms(config.sample_time_ms() * config.sample_incr());
|
config = new FindmaxConfig(
|
||||||
config.setMin_settling_ms(config.min_settling_ms() * 2);
|
(config.sample_time_ms() * config.sample_incr()),
|
||||||
|
config.max_value(),
|
||||||
|
config.base_value(),
|
||||||
|
config.min_value(),
|
||||||
|
config.step_value(),
|
||||||
|
config.value_incr(),
|
||||||
|
config.sample_incr(),
|
||||||
|
(config.min_settling_ms() * 2),
|
||||||
|
config.optimization_type(),
|
||||||
|
new double[]{newValue}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
logger.info("could not divide search space further, stop condition met");
|
logger.info("could not divide search space further, stop condition met");
|
||||||
return Double.MIN_VALUE;
|
return new FrameResult(best.params().paramValues()[0], SimFrameAction.stop_run);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double[] point = {newValue};
|
double[] point = {newValue};
|
||||||
return function.value(point);
|
return new FrameResult(function.value(point), SimFrameAction.continue_run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FrameResult initialFrame() {
|
||||||
|
return new FrameResult(function.value(config.initialPoint()), SimFrameAction.continue_run);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,105 +17,35 @@
|
|||||||
package io.nosqlbench.scenarios.simframe.optimizers.findmax;
|
package io.nosqlbench.scenarios.simframe.optimizers.findmax;
|
||||||
|
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
|
||||||
import io.nosqlbench.scenarios.simframe.planning.SimFrameConfig;
|
|
||||||
|
|
||||||
public class FindmaxConfig extends SimFrameConfig {
|
public record FindmaxConfig (
|
||||||
private double sample_time_ms;
|
double sample_time_ms,
|
||||||
private double max_value;
|
double max_value,
|
||||||
private double base_value;
|
double base_value,
|
||||||
private double min_value;
|
double min_value,
|
||||||
private double step_value;
|
double step_value,
|
||||||
private double value_incr;
|
double value_incr,
|
||||||
private double sample_incr;
|
double sample_incr,
|
||||||
private long min_settling_ms;
|
long min_settling_ms,
|
||||||
private String optimization_type;
|
String optimization_type,
|
||||||
|
double[] initial_point
|
||||||
public double sample_time_ms() {
|
) {
|
||||||
return sample_time_ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double max_value() {
|
|
||||||
return max_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double base_value() {
|
|
||||||
return base_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double[] initialPoint() {
|
public double[] initialPoint() {
|
||||||
return new double[]{base_value};
|
return new double[]{base_value};
|
||||||
}
|
}
|
||||||
|
|
||||||
public double min_value() {
|
|
||||||
return min_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double step_value() {
|
|
||||||
return step_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double value_incr() {
|
|
||||||
return value_incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double sample_incr() {
|
|
||||||
return sample_incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long min_settling_ms() {
|
|
||||||
return min_settling_ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String optimization_type() {
|
|
||||||
return optimization_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSample_time_ms(double sample_time_ms) {
|
|
||||||
this.sample_time_ms = sample_time_ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMax_value(double max_value) {
|
|
||||||
this.max_value = max_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBase_value(double base_value) {
|
|
||||||
this.base_value = base_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStep_value(double step_value) {
|
|
||||||
this.step_value = step_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMin_value(double min_value) {
|
|
||||||
this.min_value = min_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSample_incr(double sample_incr) {
|
|
||||||
this.sample_incr = sample_incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue_incr(double value_incr) {
|
|
||||||
this.value_incr = value_incr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMin_settling_ms(long min_settling_ms) {
|
|
||||||
this.min_settling_ms = min_settling_ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOptimization_type(String optimization_type) {
|
|
||||||
this.optimization_type = optimization_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FindmaxConfig(NBCommandParams params) {
|
public FindmaxConfig(NBCommandParams params) {
|
||||||
setSample_time_ms(params.maybeGet("sample_time_ms").map(Double::parseDouble).orElse(4000d));
|
this(
|
||||||
setMax_value(params.maybeGet("max_value").map(Double::parseDouble).orElse(10000d));
|
params.maybeGet("sample_time_ms").map(Double::parseDouble).orElse(4000d),
|
||||||
setBase_value(params.maybeGet("base_value").map(Double::parseDouble).orElse(10d));
|
params.maybeGet("max_value").map(Double::parseDouble).orElse(10000d),
|
||||||
setMin_value(params.maybeGet("min_value").map(Double::parseDouble).orElse(0d));
|
params.maybeGet("base_value").map(Double::parseDouble).orElse(10d),
|
||||||
setStep_value(params.maybeGet("step_value").map(Double::parseDouble).orElse(100d));
|
params.maybeGet("min_value").map(Double::parseDouble).orElse(0d),
|
||||||
setValue_incr(params.maybeGet("value_incr").map(Double::parseDouble).orElse(2d));
|
params.maybeGet("step_value").map(Double::parseDouble).orElse(100d),
|
||||||
setSample_incr(params.maybeGet("sample_incr").map(Double::parseDouble).orElse(1.2d));
|
params.maybeGet("value_incr").map(Double::parseDouble).orElse(2d),
|
||||||
setMin_settling_ms(params.maybeGet("min_settling_ms").map(Long::parseLong).orElse(4000L));
|
params.maybeGet("sample_incr").map(Double::parseDouble).orElse(1.2d),
|
||||||
setOptimization_type(params.maybeGet("optimization_type").orElse("rate"));
|
params.maybeGet("min_settling_ms").map(Long::parseLong).orElse(4000L),
|
||||||
|
params.maybeGet("optimization_type").orElse("rate"),
|
||||||
|
new double[]{params.maybeGet("base_value").map(Double::parseDouble).orElse(10d)}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,7 @@
|
|||||||
|
|
||||||
package io.nosqlbench.scenarios.simframe.planning;
|
package io.nosqlbench.scenarios.simframe.planning;
|
||||||
|
|
||||||
public abstract class SimFrameConfig {
|
public enum SimFrameAction {
|
||||||
public abstract double base_value();
|
continue_run,
|
||||||
|
stop_run
|
||||||
public abstract double[] initialPoint();
|
|
||||||
}
|
}
|
||||||
@@ -19,23 +19,25 @@ package io.nosqlbench.scenarios.simframe.planning;
|
|||||||
|
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.container.InvokableResult;
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.InvokableResult;
|
||||||
|
|
||||||
public abstract class SimFrameFunctionAnalyzer<A extends SimFrameFunction<? extends InvokableResult>, C extends SimFrameConfig> {
|
public abstract class SimFrameFunctionAnalyzer<A extends SimFrameFunction<? extends InvokableResult>, C extends Record> {
|
||||||
protected final A function;
|
protected final A function;
|
||||||
protected final C config;
|
protected C config;
|
||||||
|
|
||||||
protected SimFrameFunctionAnalyzer(A function, C config) {
|
protected SimFrameFunctionAnalyzer(A function, C config) {
|
||||||
this.function = function;
|
this.function = function;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record FrameResult(double value, SimFrameAction action) {}
|
||||||
|
|
||||||
public SimFrame<? extends InvokableResult> analyze() {
|
public SimFrame<? extends InvokableResult> analyze() {
|
||||||
double[] initialPoint = config.initialPoint();
|
FrameResult result = initialFrame();
|
||||||
double result = function.value(initialPoint);
|
while (result.action() == SimFrameAction.continue_run) {
|
||||||
while (result != Double.MIN_VALUE) {
|
|
||||||
result = nextFrame();
|
result = nextFrame();
|
||||||
}
|
}
|
||||||
return function.getJournal().bestRun();
|
return function.getJournal().bestRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract double nextFrame();
|
protected abstract FrameResult nextFrame();
|
||||||
|
protected abstract FrameResult initialFrame();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user