Skip to content

Commit 4dccb5b

Browse files
Feat/n param for bench (#244)
1 parent bea9998 commit 4dccb5b

File tree

7 files changed

+70
-6
lines changed

7 files changed

+70
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ Optionally you can use the `--run-before` param to run a query before the benchm
105105

106106
To save benchmark results to a file use the `--save` parameter with a file path. Further, you can use the `--append` parameter to append to the file instead of overwriting it.
107107

108+
The number of benchmark iterations is defined in your configuration (default is 10) and can be configured per benchmark run with `-n` parameter.
109+
108110
#### Analyze Queries
109111

110112
The output from `EXPLAIN ANALYZE` provides a wealth of information on a queries execution - however, the amount of information and connecting the dots can be difficult and manual. Further, there is detail in the `MetricSet`'s of the underlying `ExecutionPlan`'s that is lost in the output.

src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub struct DftArgs {
8787

8888
#[clap(long, help = "Append the benchmark results to an existing file")]
8989
pub append: bool,
90+
91+
#[clap(short = 'n', help = "Set the number of benchmark iterations to run")]
92+
pub benchmark_iterations: Option<usize>,
9093
}
9194

9295
impl DftArgs {

src/cli/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl CliApp {
386386
let stats = self
387387
.app_execution
388388
.execution_ctx()
389-
.benchmark_query(sql)
389+
.benchmark_query(sql, self.args.benchmark_iterations)
390390
.await?;
391391
Ok(stats)
392392
}
@@ -407,7 +407,7 @@ impl CliApp {
407407
let stats = self
408408
.app_execution
409409
.flightsql_ctx()
410-
.benchmark_query(sql)
410+
.benchmark_query(sql, self.args.benchmark_iterations)
411411
.await?;
412412
Ok(stats)
413413
}

src/execution/flightsql.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ impl FlightSQLContext {
6767
}
6868
}
6969

70-
pub async fn benchmark_query(&self, query: &str) -> Result<FlightSQLBenchmarkStats> {
71-
let iterations = self.config.benchmark_iterations;
70+
pub async fn benchmark_query(
71+
&self,
72+
query: &str,
73+
cli_iterations: Option<usize>,
74+
) -> Result<FlightSQLBenchmarkStats> {
75+
let iterations = cli_iterations.unwrap_or(self.config.benchmark_iterations);
7276
let mut rows_returned = Vec::with_capacity(iterations);
7377
let mut get_flight_info_durations = Vec::with_capacity(iterations);
7478
let mut ttfb_durations = Vec::with_capacity(iterations);

src/execution/local.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,12 @@ impl ExecutionContext {
243243
}
244244

245245
/// Benchmark the provided query. Currently, only a single statement can be benchmarked
246-
pub async fn benchmark_query(&self, query: &str) -> Result<LocalBenchmarkStats> {
247-
let iterations = self.config.benchmark_iterations;
246+
pub async fn benchmark_query(
247+
&self,
248+
query: &str,
249+
cli_iterations: Option<usize>,
250+
) -> Result<LocalBenchmarkStats> {
251+
let iterations = cli_iterations.unwrap_or(self.config.benchmark_iterations);
248252
info!("Benchmarking query with {} iterations", iterations);
249253
let mut rows_returned = Vec::with_capacity(iterations);
250254
let mut logical_planning_durations = Vec::with_capacity(iterations);

tests/cli_cases/bench.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,24 @@ SELECT 1
179179
let lines: Vec<&str> = contents.lines().collect();
180180
assert_eq!(lines.len(), 3);
181181
}
182+
183+
#[test]
184+
fn test_bench_command_with_custom_iterations() {
185+
let assert = Command::cargo_bin("dft")
186+
.unwrap()
187+
.arg("-c")
188+
.arg("SELECT 1")
189+
.arg("--bench")
190+
.arg("-n")
191+
.arg("3")
192+
.assert()
193+
.success();
194+
195+
let expected = r##"
196+
----------------------------
197+
Benchmark Stats (3 runs)
198+
----------------------------
199+
SELECT 1
200+
----------------------------"##;
201+
assert.stdout(contains_str(expected));
202+
}

tests/extension_cases/flightsql.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,33 @@ SELECT 1
465465

466466
fixture.shutdown_and_wait().await;
467467
}
468+
469+
#[tokio::test]
470+
pub async fn test_bench_command_customer_iterations() {
471+
let test_server = TestFlightSqlServiceImpl::new();
472+
let fixture = TestFixture::new(test_server.service(), "127.0.0.1:50051").await;
473+
474+
let assert = tokio::task::spawn_blocking(move || {
475+
Command::cargo_bin("dft")
476+
.unwrap()
477+
.arg("-c")
478+
.arg("SELECT 1")
479+
.arg("--bench")
480+
.arg("--flightsql")
481+
.arg("-n")
482+
.arg("3")
483+
.assert()
484+
.success()
485+
})
486+
.await
487+
.unwrap();
488+
489+
let expected = r##"
490+
----------------------------
491+
Benchmark Stats (3 runs)
492+
----------------------------
493+
SELECT 1
494+
----------------------------"##;
495+
assert.stdout(contains_str(expected));
496+
fixture.shutdown_and_wait().await;
497+
}

0 commit comments

Comments
 (0)