Skip to content

Commit 944e699

Browse files
committed
Improving fine tune step
- Avoiding calculating current score initially if it's already been calculated - Fix tune up step not going down until 1 - Improve code readability
1 parent e3dfaba commit 944e699

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

cli/src/main/java/com/v1ct04/benchstack/driver/Benchmark.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,19 @@ private Statistics executeBenchmark() throws InterruptedException {
8282

8383
execBinarySearchStep(mConfig.getBinarySearchConfig(), searchLimits);
8484

85-
do {
86-
double score = execFineTuneStep(mConfig.getFineTuneConfig());
85+
double score = execFineTuneStep(mConfig.getFineTuneConfig());
8786

88-
if (score > 0) {
89-
break;
90-
} else if (score < -2 * mConfig.getFineTuneConfig().getInitialStep()) {
87+
while (score < 0) {
88+
if (score < -2 * mConfig.getFineTuneConfig().getMaxInitialStep()) {
9189
logInfoAndStdOut("Unexpectedly bad result from fine tune, doing binary search again.");
9290
searchLimits = searchLimits.intersection(Range.atMost(mWorkersPool.getWorkerCount()));
9391
execBinarySearchStep(mConfig.getBinarySearchConfig(), searchLimits);
9492
} else {
9593
logInfoAndStdOut("Fine tune result uncompliant, will try again.");
9694
}
97-
} while (true);
95+
96+
score = execFineTuneStep(mConfig.getFineTuneConfig(), score);
97+
}
9898

9999
Statistics stats = execCalculateStatsStep(mConfig.getStableStatsConfig());
100100
printFinalResults(stats);
@@ -154,19 +154,25 @@ private void execBinarySearchStep(BinarySearchStepConfig config, Range<Integer>
154154
}
155155

156156
private double execFineTuneStep(FineTuneStepConfig config) throws InterruptedException {
157+
return execFineTuneStep(config, Double.NaN);
158+
}
159+
160+
private double execFineTuneStep(FineTuneStepConfig config, double score) throws InterruptedException {
157161
logInfoAndStdOut("Starting fine tune step.");
158162

159-
double score = complianceScore(config);
160-
if (score < 0) {
161-
int tuneDownStep = 2 * (int) Math.min(Math.round(-score), config.getInitialStep());
162-
do {
163-
LOGGER.debug("Fine tuning down with step: {}", tuneDownStep);
164-
setWorkerCount(Math.max(mWorkersPool.getWorkerCount() - tuneDownStep, 0));
165-
} while (!isComplying(config));
163+
if (Double.isNaN(score)) {
164+
score = complianceScore(config);
165+
}
166+
int tuneDownStep = 2 * (int) Math.min(Math.round(-score), config.getMaxInitialStep());
167+
while (score < 0) {
168+
LOGGER.debug("Fine tuning down with step: {}", tuneDownStep);
169+
setWorkerCount(Math.max(mWorkersPool.getWorkerCount() - tuneDownStep, 0));
170+
score = complianceScore(config);
166171
}
167172

168173
int complyingCount = mWorkersPool.getWorkerCount();
169-
for (int step = config.getInitialStep(); step > 1; step /= 2) {
174+
int initialStep = (int) Math.min(Math.round(2 * score), config.getMaxInitialStep());
175+
for (int step = initialStep; step >= 1; step /= 2) {
170176
while (true) {
171177
LOGGER.debug("Fine tuning up with step: {}", step);
172178
setWorkerCount(complyingCount + step);

cli/src/main/proto/benchmark_config.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ message BenchmarkConfig {
2121

2222
message FineTuneStepConfig {
2323
optional int64 baseWaitTimeSec = 1 [default = 20];
24-
optional int32 initialStep = 2 [default = 10];
24+
optional int32 maxInitialStep = 2 [default = 10];
2525
}
2626

2727
message StableStatsStepConfig {

0 commit comments

Comments
 (0)