mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
finished generification
This commit is contained in:
committed by
Jonathan Shook
parent
08bd1ca029
commit
7d961cb351
@@ -20,6 +20,7 @@ import io.nosqlbench.engine.api.activityapi.core.Activity;
|
|||||||
import io.nosqlbench.engine.api.activityapi.simrate.CycleRateSpec;
|
import io.nosqlbench.engine.api.activityapi.simrate.CycleRateSpec;
|
||||||
import io.nosqlbench.engine.api.activityapi.simrate.SimRateSpec;
|
import io.nosqlbench.engine.api.activityapi.simrate.SimRateSpec;
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
|
||||||
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.InvokableResult;
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBBaseCommand;
|
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBBaseCommand;
|
||||||
@@ -31,6 +32,7 @@ import io.nosqlbench.scenarios.simframe.capture.SimFrameJournal;
|
|||||||
import io.nosqlbench.scenarios.simframe.capture.SimFrameValueData;
|
import io.nosqlbench.scenarios.simframe.capture.SimFrameValueData;
|
||||||
import io.nosqlbench.scenarios.simframe.optimizers.CMD_optimize;
|
import io.nosqlbench.scenarios.simframe.optimizers.CMD_optimize;
|
||||||
import io.nosqlbench.scenarios.simframe.planning.SimFrame;
|
import io.nosqlbench.scenarios.simframe.planning.SimFrame;
|
||||||
|
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunctionAnalyzer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -80,8 +82,8 @@ public class CMD_findmax extends NBBaseCommand {
|
|||||||
|
|
||||||
SimFrameCapture capture = new SimFrameValueData(flywheel);
|
SimFrameCapture capture = new SimFrameValueData(flywheel);
|
||||||
FindmaxFrameFunction frameFunction = new FindmaxFrameFunction(controller, findmaxConfig, flywheel, capture, journal, model);
|
FindmaxFrameFunction frameFunction = new FindmaxFrameFunction(controller, findmaxConfig, flywheel, capture, journal, model);
|
||||||
FindmaxAnalyzer analyzer = new FindmaxAnalyzer(frameFunction, findmaxConfig);
|
SimFrameFunctionAnalyzer<FindmaxFrameFunction,FindmaxConfig> analyzer = new FindmaxAnalyzer(frameFunction, findmaxConfig);
|
||||||
SimFrame<FindmaxFrameParams> best = analyzer.analyze();
|
SimFrame<? extends InvokableResult> best = analyzer.analyze();
|
||||||
stdout.println("Best Run:\n" + best);
|
stdout.println("Best Run:\n" + best);
|
||||||
return best.params();
|
return best.params();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,27 +24,17 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
import static io.nosqlbench.virtdata.core.bindings.VirtDataLibrary.logger;
|
import static io.nosqlbench.virtdata.core.bindings.VirtDataLibrary.logger;
|
||||||
|
|
||||||
public class FindmaxAnalyzer implements SimFrameFunctionAnalyzer {
|
public class FindmaxAnalyzer extends SimFrameFunctionAnalyzer<FindmaxFrameFunction,FindmaxConfig> {
|
||||||
private final FindmaxFrameFunction function;
|
|
||||||
private final FindmaxConfig config;
|
|
||||||
|
|
||||||
public FindmaxAnalyzer(FindmaxFrameFunction function, FindmaxConfig config) {
|
public FindmaxAnalyzer(FindmaxFrameFunction function, FindmaxConfig config) {
|
||||||
this.function = function;
|
super(function, config);
|
||||||
this.config = config;
|
|
||||||
}
|
|
||||||
public SimFrame<FindmaxFrameParams> analyze() {
|
|
||||||
double[] initialPoint = {config.base_value()};
|
|
||||||
double result = function.value(initialPoint);
|
|
||||||
while (result != 0.0d) {
|
|
||||||
result = nextStep();
|
|
||||||
}
|
|
||||||
return function.journal().bestRun();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double nextStep() {
|
@Override
|
||||||
|
protected double nextFrame() {
|
||||||
double newValue;
|
double newValue;
|
||||||
SimFrame<FindmaxFrameParams> last = function.journal().last();
|
SimFrame<FindmaxFrameParams> last = function.getJournal().last();
|
||||||
SimFrame<FindmaxFrameParams> best = function.journal().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.setStep_value(config.step_value() * config.value_incr());
|
||||||
@@ -53,7 +43,7 @@ public class FindmaxAnalyzer implements SimFrameFunctionAnalyzer {
|
|||||||
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 0;
|
return Double.MIN_VALUE;
|
||||||
} 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.setSample_time_ms(config.sample_time_ms() * config.sample_incr());
|
||||||
@@ -61,7 +51,7 @@ public class FindmaxAnalyzer implements SimFrameFunctionAnalyzer {
|
|||||||
}
|
}
|
||||||
} 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
|
||||||
SimFrame<FindmaxFrameParams> nextWorseFrameWithHigherRate = function.journal().frames().stream()
|
SimFrame<FindmaxFrameParams> nextWorseFrameWithHigherRate = function.getJournal().frames().stream()
|
||||||
.filter(f -> f.value() < best.value())
|
.filter(f -> f.value() < best.value())
|
||||||
.filter(f -> f.params().paramValues()[0] + config.step_value() > (best.params().paramValues()[0] + config.step_value()))
|
.filter(f -> f.params().paramValues()[0] + config.step_value() > (best.params().paramValues()[0] + config.step_value()))
|
||||||
.min(Comparator.comparingDouble(f -> f.params().paramValues()[0] + config.step_value()))
|
.min(Comparator.comparingDouble(f -> f.params().paramValues()[0] + config.step_value()))
|
||||||
@@ -73,7 +63,7 @@ public class FindmaxAnalyzer implements SimFrameFunctionAnalyzer {
|
|||||||
config.setMin_settling_ms(config.min_settling_ms() * 2);
|
config.setMin_settling_ms(config.min_settling_ms() * 2);
|
||||||
} 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 0.0d;
|
return Double.MIN_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double[] point = {newValue};
|
double[] point = {newValue};
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
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 {
|
public class FindmaxConfig extends SimFrameConfig {
|
||||||
private double sample_time_ms;
|
private double sample_time_ms;
|
||||||
private double max_value;
|
private double max_value;
|
||||||
private double base_value;
|
private double base_value;
|
||||||
@@ -41,6 +42,11 @@ public class FindmaxConfig {
|
|||||||
return base_value;
|
return base_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double[] initialPoint() {
|
||||||
|
return new double[]{base_value};
|
||||||
|
}
|
||||||
|
|
||||||
public double min_value() {
|
public double min_value() {
|
||||||
return min_value;
|
return min_value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import io.nosqlbench.scenarios.simframe.capture.SimFrameCapture;
|
|||||||
import io.nosqlbench.scenarios.simframe.capture.SimFrameJournal;
|
import io.nosqlbench.scenarios.simframe.capture.SimFrameJournal;
|
||||||
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunction;
|
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunction;
|
||||||
|
|
||||||
public class FindmaxFrameFunction implements SimFrameFunction {
|
public class FindmaxFrameFunction implements SimFrameFunction<FindmaxFrameParams> {
|
||||||
|
|
||||||
private final Activity flywheel;
|
private final Activity flywheel;
|
||||||
private final SimFrameCapture capture;
|
private final SimFrameCapture capture;
|
||||||
@@ -69,7 +69,8 @@ public class FindmaxFrameFunction implements SimFrameFunction {
|
|||||||
return journal.last().value();
|
return journal.last().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimFrameJournal<FindmaxFrameParams> journal() {
|
@Override
|
||||||
|
public SimFrameJournal<FindmaxFrameParams> getJournal() {
|
||||||
return journal;
|
return journal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import io.nosqlbench.scenarios.simframe.capture.SimFrameCapture;
|
|||||||
import io.nosqlbench.scenarios.simframe.capture.SimFrameJournal;
|
import io.nosqlbench.scenarios.simframe.capture.SimFrameJournal;
|
||||||
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunction;
|
import io.nosqlbench.scenarios.simframe.planning.SimFrameFunction;
|
||||||
|
|
||||||
public class OptimoFrameFunction implements SimFrameFunction {
|
public class OptimoFrameFunction implements SimFrameFunction<OptimoFrameParams> {
|
||||||
|
|
||||||
private final Activity flywheel;
|
private final Activity flywheel;
|
||||||
private final SimFrameCapture capture;
|
private final SimFrameCapture capture;
|
||||||
@@ -65,4 +65,9 @@ public class OptimoFrameFunction implements SimFrameFunction {
|
|||||||
}
|
}
|
||||||
return journal.last().value();
|
return journal.last().value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SimFrameJournal<OptimoFrameParams> getJournal() {
|
||||||
|
return journal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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.planning;
|
||||||
|
|
||||||
|
public abstract class SimFrameConfig {
|
||||||
|
public abstract double base_value();
|
||||||
|
|
||||||
|
public abstract double[] initialPoint();
|
||||||
|
}
|
||||||
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package io.nosqlbench.scenarios.simframe.planning;
|
package io.nosqlbench.scenarios.simframe.planning;
|
||||||
|
|
||||||
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.InvokableResult;
|
||||||
|
import io.nosqlbench.scenarios.simframe.capture.SimFrameJournal;
|
||||||
import org.apache.commons.math4.legacy.analysis.MultivariateFunction;
|
import org.apache.commons.math4.legacy.analysis.MultivariateFunction;
|
||||||
|
|
||||||
public interface SimFrameFunction extends MultivariateFunction {
|
public interface SimFrameFunction<P extends InvokableResult> extends MultivariateFunction {
|
||||||
@Override
|
@Override
|
||||||
double value(double[] point);
|
double value(double[] point);
|
||||||
|
|
||||||
|
SimFrameJournal<P> getJournal();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,25 @@
|
|||||||
|
|
||||||
package io.nosqlbench.scenarios.simframe.planning;
|
package io.nosqlbench.scenarios.simframe.planning;
|
||||||
|
|
||||||
public interface SimFrameFunctionAnalyzer {
|
import io.nosqlbench.engine.core.lifecycle.scenario.container.InvokableResult;
|
||||||
|
|
||||||
|
public abstract class SimFrameFunctionAnalyzer<A extends SimFrameFunction<? extends InvokableResult>, C extends SimFrameConfig> {
|
||||||
|
protected final A function;
|
||||||
|
protected final C config;
|
||||||
|
|
||||||
|
protected SimFrameFunctionAnalyzer(A function, C config) {
|
||||||
|
this.function = function;
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimFrame<? extends InvokableResult> analyze() {
|
||||||
|
double[] initialPoint = config.initialPoint();
|
||||||
|
double result = function.value(initialPoint);
|
||||||
|
while (result != Double.MIN_VALUE) {
|
||||||
|
result = nextFrame();
|
||||||
|
}
|
||||||
|
return function.getJournal().bestRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract double nextFrame();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user