From ff25f824d63494fa9a021d5c4f333c900b9909b2 Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Mon, 18 Dec 2023 15:02:56 -0600 Subject: [PATCH] partial improvements --- .../findmax/planners/FindmaxPlannerType.java | 7 +- .../planners/{ => rampup}/FindmaxRampup.java | 30 ++++---- .../rampup/RampupConfig.java} | 6 +- .../rampup/RampupFrameParams.java} | 4 +- .../findmax/survey/FindmaxSurvey.java | 68 +++++++++++++++++++ .../simframe/findmax/survey/SurveyConfig.java | 36 ++++++++++ .../findmax/survey/SurveyFrameParams.java | 25 +++++++ 7 files changed, 153 insertions(+), 23 deletions(-) rename nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/{ => rampup}/FindmaxRampup.java (81%) rename nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/{FindmaxSearchParams.java => planners/rampup/RampupConfig.java} (92%) rename nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/{FindMaxFrameParams.java => planners/rampup/RampupFrameParams.java} (95%) create mode 100644 nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/FindmaxSurvey.java create mode 100644 nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyConfig.java create mode 100644 nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyFrameParams.java diff --git a/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxPlannerType.java b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxPlannerType.java index 807898495..9bf6b8b8c 100644 --- a/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxPlannerType.java +++ b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxPlannerType.java @@ -17,19 +17,22 @@ package io.nosqlbench.scenarios.simframe.findmax.planners; import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams; +import io.nosqlbench.scenarios.simframe.findmax.planners.rampup.FindmaxRampup; import io.nosqlbench.scenarios.simframe.findmax.planners.ratchet.FindmaxRatchet; +import io.nosqlbench.scenarios.simframe.findmax.survey.FindmaxSurvey; import io.nosqlbench.scenarios.simframe.planning.SimFramePlanner; public enum FindmaxPlannerType { // survey, ratchet, - rampup; + rampup, + survey, ; public SimFramePlanner createPlanner(NBCommandParams params) { return switch (this) { case ratchet -> new FindmaxRatchet(params); -// case survey -> new FindmaxSurvey(params); case rampup -> new FindmaxRampup(params); + case survey -> new FindmaxSurvey(params); }; } } diff --git a/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxRampup.java b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/rampup/FindmaxRampup.java similarity index 81% rename from nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxRampup.java rename to nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/rampup/FindmaxRampup.java index 7d43be33b..fa757d8b5 100644 --- a/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/FindmaxRampup.java +++ b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/planners/rampup/FindmaxRampup.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.nosqlbench.scenarios.simframe.findmax.planners; +package io.nosqlbench.scenarios.simframe.findmax.planners.rampup; import io.nosqlbench.engine.api.activityapi.core.Activity; import io.nosqlbench.engine.api.activityapi.ratelimits.simrate.CycleRateSpec; @@ -22,8 +22,6 @@ import io.nosqlbench.engine.api.activityapi.ratelimits.simrate.SimRateSpec; import io.nosqlbench.engine.core.lifecycle.scenario.container.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; @@ -31,7 +29,7 @@ import org.apache.logging.log4j.Logger; import java.util.Comparator; -public class FindmaxRampup extends SimFramePlanner { +public class FindmaxRampup extends SimFramePlanner { private final Logger logger = LogManager.getLogger(FindmaxRampup.class); public FindmaxRampup(NBCommandParams analyzerParams) { @@ -39,12 +37,12 @@ public class FindmaxRampup extends SimFramePlanner journal) { - SimFrame last = journal.last(); - SimFrame best = journal.bestRun(); + public RampupFrameParams nextStep(JournalView journal) { + SimFrame last = journal.last(); + SimFrame best = journal.bestRun(); if (best.index() == last.index()) { // got better consecutively - return new FindMaxFrameParams( + return new RampupFrameParams( last.params().rate_shelf(), last.params().rate_delta() * config.rate_incr(), last.params().sample_time_ms(), @@ -76,7 +74,7 @@ public class FindmaxRampup extends SimFramePlanner nextWorseFrameWithHigherRate = journal.frames().stream() + SimFrame 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())) .orElseThrow(() -> new RuntimeException("inconsistent samples")); if ((nextWorseFrameWithHigherRate.params().computed_rate() - best.params().computed_rate()) > config.rate_step()) { - return new FindMaxFrameParams( + return new RampupFrameParams( best.params().computed_rate(), config.rate_step(), (long) (last.params().sample_time_ms() * config.sample_incr()), @@ -107,7 +105,7 @@ public class FindmaxRampup extends SimFramePlanner { + private final Logger logger = LogManager.getLogger(FindmaxSurvey.class); + + public FindmaxSurvey(NBCommandParams params) { + super(params); + } + + + @Override + public SurveyConfig getConfig(NBCommandParams params) { + return new SurveyConfig(params); + } + + public SurveyFrameParams initialStep() { + return new SurveyFrameParams(config.max_rate(), config.steps(), "INITIAL"); + } + + /** + * Using a stateful history of all control parameters and all results, decide if there + * is additional search space and return a set of parameters for the next workload + * simulation frame. If the stopping condition has been met, return null + * + * @param journal + * All parameters and results, organized in enumerated simulation frames + * @return Optionally, a set of paramValues which indicates another simulation frame should be sampled, else null + */ + + @Override + public SurveyFrameParams nextStep(JournalView journal) { + return null; + } + + + @Override + public void applyParams(SurveyFrameParams params, Activity flywheel) { + flywheel.onEvent(ParamChange.of(new CycleRateSpec(params.rate(), 1.1d, SimRateSpec.Verb.restart))); + + } +} diff --git a/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyConfig.java b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyConfig.java new file mode 100644 index 000000000..6a7eb67ca --- /dev/null +++ b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyConfig.java @@ -0,0 +1,36 @@ +/* + * 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.findmax.survey; + +import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams; + +/** + * These search parameters are based on the original findmax algorithm, and + * should be reduced down to the minimum set needed. + */ +public record SurveyConfig( + double max_rate, + int steps +) { + public SurveyConfig(NBCommandParams params) { + this( + params.maybeGet("max_rate").map(Double::parseDouble).orElse(1.2d), + params.maybeGet("steps").map(Integer::parseInt).orElse(3) + ); + + } +} diff --git a/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyFrameParams.java b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyFrameParams.java new file mode 100644 index 000000000..411becca1 --- /dev/null +++ b/nbr/src/main/java/io/nosqlbench/scenarios/simframe/findmax/survey/SurveyFrameParams.java @@ -0,0 +1,25 @@ +/* + * 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.findmax.survey; + +public record SurveyFrameParams( + double rate, + double step, + String description + +) { +}