Skip to content

Commit e3bc7a3

Browse files
committed
Add dummy optimization support
1 parent 5a4f9d7 commit e3bc7a3

94 files changed

Lines changed: 187897 additions & 29 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dummy/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ You can execute the driver with three modes, and you should update the mode in t
44
- CREATE_VALIDATION
55
- VALIDATE_DATABASE
66
- EXECUTE_BENCHMARK
7+
- OPTIMIZATION_RECOMMENDATION
78

89
execute:
910
```
@@ -12,4 +13,25 @@ java -cp xxx.jar org.ldbcouncil.finbench.driver.driver.Driver -P example.propert
1213

1314
debug:
1415
- add VM options `-P src/main/resources/example/example.properties`
15-
- run `Driver.main`
16+
- run `Driver.main`
17+
# Dummy Optimization Support
18+
19+
`DummyDb` implements the optional FinBench `OptimizationSupport` capability. It samples the
20+
current JVM CPU and memory usage, runs a representative operation for resource profiling, and then
21+
executes bounded synthetic CPU/memory/duration loads for `OPTIMIZATION_RECOMMENDATION` mode tests.
22+
23+
The dummy implementation caps each synthetic memory allocation at 16 MiB to keep local tests safe.
24+
25+
Run the optimization recommendation example after building the dummy module:
26+
27+
```bash
28+
mvn -pl dummy -am package -DskipTests
29+
cd dummy
30+
sh run_optimization_recommendation.sh
31+
```
32+
33+
The script uses `src/main/resources/example/optimization_recommendation.properties` by default
34+
and writes `optimization-report.md` and `optimization-report.json` under the configured `results_dir`.
35+
You can tune
36+
`optimization.top_n`, `optimization.reduction_steps`, `optimization.profile_repetitions`, and
37+
`optimization.repetitions` in that properties file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java -cp target/dummy-0.2.0-alpha.jar org.ldbcouncil.finbench.driver.driver.Driver -P src/main/resources/example/optimization_recommendation.properties

dummy/src/main/java/org/ldbcouncil/finbench/impls/dummy/DummyDb.java

Lines changed: 106 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.ldbcouncil.finbench.impls.dummy;
2+
3+
import com.sun.management.OperatingSystemMXBean;
4+
import java.lang.management.ManagementFactory;
5+
import java.util.concurrent.TimeUnit;
6+
import org.ldbcouncil.finbench.driver.DbException;
7+
import org.ldbcouncil.finbench.driver.optimization.OptimizationSupport;
8+
import org.ldbcouncil.finbench.driver.optimization.OperationProfileSpec;
9+
import org.ldbcouncil.finbench.driver.optimization.ResourceSnapshot;
10+
import org.ldbcouncil.finbench.driver.optimization.SyntheticExecutionResult;
11+
import org.ldbcouncil.finbench.driver.optimization.SyntheticLoadSpec;
12+
13+
/**
14+
* Test implementation that models CPU, memory and duration inside the driver JVM.
15+
*/
16+
public class DummyOptimizationSupport implements OptimizationSupport {
17+
private static final long MAX_TEST_ALLOCATION_BYTES = 16L * 1024 * 1024;
18+
19+
@Override
20+
public ResourceSnapshot sampleResources() {
21+
Runtime runtime = Runtime.getRuntime();
22+
long usedMemory = runtime.totalMemory() - runtime.freeMemory();
23+
double cpuCores = 0;
24+
java.lang.management.OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
25+
if (bean instanceof OperatingSystemMXBean) {
26+
OperatingSystemMXBean osBean = (OperatingSystemMXBean) bean;
27+
double processLoad = osBean.getProcessCpuLoad();
28+
if (processLoad >= 0) {
29+
cpuCores = processLoad * osBean.getAvailableProcessors();
30+
}
31+
}
32+
return new ResourceSnapshot(System.currentTimeMillis(), cpuCores, usedMemory);
33+
}
34+
35+
@Override
36+
public SyntheticExecutionResult executeRepresentativeOperation(OperationProfileSpec spec) throws DbException {
37+
long durationMillis = Math.max(1, spec.expectedDurationMillis());
38+
long memoryBytes = 1024L * Math.max(1, spec.operationName().length());
39+
return executeSyntheticLoad(new SyntheticLoadSpec(spec.operationName(), 0.25, memoryBytes, durationMillis));
40+
}
41+
42+
@Override
43+
public SyntheticExecutionResult executeSyntheticLoad(SyntheticLoadSpec spec) throws DbException {
44+
if (spec.targetDurationMillis() < 0 || spec.targetMemoryBytes() < 0 || spec.targetCpuCores() < 0) {
45+
throw new DbException("Synthetic load values must be non-negative");
46+
}
47+
48+
int allocationSize = (int) Math.min(spec.targetMemoryBytes(), MAX_TEST_ALLOCATION_BYTES);
49+
byte[] allocation = allocationSize == 0 ? null : new byte[allocationSize];
50+
if (allocation != null) {
51+
for (int offset = 0; offset < allocation.length; offset += 4096) {
52+
allocation[offset] = 1;
53+
}
54+
}
55+
56+
long start = System.nanoTime();
57+
long deadline = start + TimeUnit.MILLISECONDS.toNanos(spec.targetDurationMillis());
58+
if (spec.targetCpuCores() > 0) {
59+
long value = 1;
60+
while (System.nanoTime() < deadline) {
61+
value = value * 31 + 17;
62+
}
63+
if (allocation != null) {
64+
allocation[0] = (byte) value;
65+
}
66+
} else {
67+
sleepUntil(deadline);
68+
}
69+
long durationMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
70+
return new SyntheticExecutionResult(durationMillis, allocationSize);
71+
}
72+
73+
private static void sleepUntil(long deadline) throws DbException {
74+
while (System.nanoTime() < deadline) {
75+
long remainingNanos = deadline - System.nanoTime();
76+
try {
77+
TimeUnit.NANOSECONDS.sleep(remainingNanos);
78+
} catch (InterruptedException e) {
79+
Thread.currentThread().interrupt();
80+
throw new DbException("Synthetic load interrupted", e);
81+
}
82+
}
83+
}
84+
}

dummy/src/main/resources/example/data/historical_data/account_0_0.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

dummy/src/main/resources/example/data/historical_data/account_reply_loan_0_0.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

dummy/src/main/resources/example/data/historical_data/account_transfer_account_0_0.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

dummy/src/main/resources/example/data/historical_data/account_withdraw_account_0_0.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

dummy/src/main/resources/example/data/historical_data/company_0_0.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

dummy/src/main/resources/example/data/historical_data/company_apply_loan_0_0.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)