Skip to content

Commit 3539b49

Browse files
committed
benchmark: warm caches before timed queries
1 parent 796ad51 commit 3539b49

4 files changed

Lines changed: 48 additions & 9 deletions

File tree

benchmark/clickbench/as_clickbench_benchmark.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,15 @@ int RunASClickBenchBenchmark(const string &db_path, const string &queries_dir, c
664664
}
665665
query_sql = RewriteAsQueryForSampleAggregation(as_sql, as_m);
666666
}
667-
double as_median =
668-
RunMedian(con, query_sql, 5, "SIMD-AS " + entry.label + " m=" + std::to_string(as_m));
667+
string warmup_error;
668+
double as_median = -1;
669+
if (!RunSql(con, query_sql, warmup_error)) {
670+
Log("SIMD-AS " + entry.label + " m=" + std::to_string(as_m) + " warmup error: " + warmup_error);
671+
} else {
672+
Log("SIMD-AS " + entry.label + " m=" + std::to_string(as_m) + " warmup complete");
673+
as_median =
674+
RunMedian(con, query_sql, 5, "SIMD-AS " + entry.label + " m=" + std::to_string(as_m));
675+
}
669676
csv << entry.label << ",SIMD-AS," << as_m << "," << FormatNumber(as_median) << "\n";
670677
}
671678
con.Query("SET priv_rewrite=true;");

benchmark/dp/dp_benchmark_runner.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,8 +1905,8 @@ static DatasetRun CreateDatasetRun(const Config &config, const DatasetConfig &da
19051905
}
19061906
result.points = BuildRunPoints(dataset);
19071907
result.db_path = DefaultDbPath(dataset);
1908-
if (!(dataset.name == "tpch" || dataset.name == "sqlstorm_tpch") &&
1909-
!dataset.allow_create && !FileExists(result.db_path)) {
1908+
if (!(dataset.name == "tpch" || dataset.name == "sqlstorm_tpch") && !dataset.allow_create &&
1909+
!FileExists(result.db_path)) {
19101910
throw std::runtime_error("database does not exist for dataset " + dataset.name + ": " + result.db_path);
19111911
}
19121912

@@ -1975,6 +1975,14 @@ static void PrepareDatasetRun(const Config &config, DatasetRun &dataset_run,
19751975
PrepareDataset(*dataset_run.connection, dataset_run.config, false);
19761976
}
19771977

1978+
static void ExecuteBenchmarkQuery(Connection &con, const BenchmarkRow &row, const QuerySpec &query) {
1979+
if (row.point.mode == "dp_sass_bounded_ratio") {
1980+
ReadScalarDouble(con, BuildQ14BoundedSampledRatioSql(row.point.epsilon, row.point.sample_lanes));
1981+
} else {
1982+
MaterializeQuery(con, query.sql);
1983+
}
1984+
}
1985+
19781986
static void RunTimingPass(const Config &config, DatasetRun &dataset_run) {
19791987
auto &con = *dataset_run.connection;
19801988
vector<double> pu_counts(dataset_run.queries.size(), -1.0);
@@ -1997,12 +2005,11 @@ static void RunTimingPass(const Config &config, DatasetRun &dataset_run) {
19972005
RunStatement(con, "SET privacy_noise=true");
19982006
RunStatement(con, "SET privacy_seed=" + std::to_string(row.seed));
19992007

2008+
ExecuteBenchmarkQuery(con, row, query);
2009+
Log("warmup " + dataset_run.config.name + " " + row.point.mode + " " + query.name + " run " +
2010+
std::to_string(row.run) + " complete");
20002011
auto start = std::chrono::steady_clock::now();
2001-
if (row.point.mode == "dp_sass_bounded_ratio") {
2002-
ReadScalarDouble(con, BuildQ14BoundedSampledRatioSql(row.point.epsilon, row.point.sample_lanes));
2003-
} else {
2004-
MaterializeQuery(con, query.sql);
2005-
}
2012+
ExecuteBenchmarkQuery(con, row, query);
20062013
auto end = std::chrono::steady_clock::now();
20072014
row.time_ms = std::chrono::duration<double, std::milli>(end - start).count();
20082015
row.runtime_success = true;

benchmark/tpch/as_tpch_benchmark.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,16 @@ int RunASTPCHBenchmark(const string &db_path, const string &queries_dir, double
10481048
query_sql = RewriteAsQueryForSampleAggregation(as_sql, as_m);
10491049
}
10501050
}
1051+
con.Query("SET pac_m=" + std::to_string(as_m) + ";");
1052+
con.Query("SET priv_rewrite=false;");
1053+
auto r_warmup = con.Query(query_sql);
1054+
if (r_warmup && r_warmup->HasError()) {
1055+
Log("AS (" + mode_str + ") " + entry.label + " m=" + std::to_string(as_m) +
1056+
" warmup error: " + r_warmup->GetError());
1057+
csv << entry.label << "," << mode_str << "," << as_m << ",-1\n";
1058+
continue;
1059+
}
1060+
Log("AS (" + mode_str + ") " + entry.label + " m=" + std::to_string(as_m) + " warmup complete");
10511061
// Run AS query 5 times, take median
10521062
vector<double> as_times_ms;
10531063
bool as_failed = false;
@@ -1113,6 +1123,14 @@ int RunASTPCHBenchmark(const string &db_path, const string &queries_dir, double
11131123
if (!setup_ok) {
11141124
csv << entry.label << ",Naive-AS,64,-1\n";
11151125
} else {
1126+
auto r_warmup = con.Query(execute_sql);
1127+
if (r_warmup && r_warmup->HasError()) {
1128+
Log("Naive-AS " + entry.label + " warmup error: " + r_warmup->GetError());
1129+
csv << entry.label << ",Naive-AS,64,-1\n";
1130+
con.Query("DEALLOCATE PREPARE run_query;");
1131+
continue;
1132+
}
1133+
Log("Naive-AS " + entry.label + " warmup complete");
11161134
// Time EXECUTE 5 times, take median
11171135
vector<double> naive_as_times_ms;
11181136
bool naive_as_failed = false;

repro.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ build/release/extension/privacy/as_tpch_benchmark \
8787
--config benchmark/configs/utility/as_tpch_sf30.json
8888
```
8989

90+
Each AS query/mode is executed once without timing before its five measured executions. The CSV reports their median.
91+
9092
The variable-`m` configuration measures the separate aggregate path for `m=128,256,512`. It reuses the same database
9193
and skips the naive implementation.
9294

@@ -111,6 +113,8 @@ build/release/extension/privacy/as_clickbench_benchmark \
111113
--config benchmark/configs/utility/as_clickbench_graviton.json
112114
```
113115

116+
Each AS query/mode is executed once without timing before its five measured executions. The CSV reports their median.
117+
114118
Output: `benchmark/results/utility/as_clickbench_graviton.csv`.
115119

116120
### DP utility and runtime
@@ -134,6 +138,9 @@ build/release/extension/privacy/dp_benchmark_runner \
134138
--config benchmark/configs/utility/dp_tpch_sf30_utility.json
135139
```
136140

141+
The runner executes one untimed warmup immediately before every measured private-query execution. Utility and diagnostic
142+
queries run separately and are not included in `time_ms`.
143+
137144
Output: `benchmark/results/utility/dp_tpch_sf30_utility.csv`.
138145

139146
The runner deliberately uses two passes. It first times every private query and checkpoints the CSV after each

0 commit comments

Comments
 (0)