(self)
| 76 | |
| 77 | impl RunOpt { |
| 78 | pub async fn run(self) -> Result<()> { |
| 79 | println!("Running benchmarks with the following options: {self:?}"); |
| 80 | let queries = AllQueries::try_new(&self.queries_path)?; |
| 81 | let query_range = match self.query { |
| 82 | Some(query_id) => query_id..=query_id, |
| 83 | None => queries.min_query_id()..=queries.max_query_id(), |
| 84 | }; |
| 85 | |
| 86 | let config = self.common.config()?; |
| 87 | let rt = self.common.build_runtime()?; |
| 88 | let ctx = SessionContext::new_with_config_rt(config, rt); |
| 89 | |
| 90 | // Register tables depending on which h2o benchmark is being run |
| 91 | // (groupby/join/window) |
| 92 | if self.queries_path.to_str().unwrap().ends_with("groupby.sql") { |
| 93 | self.register_data("x", self.path.as_os_str().to_str().unwrap(), &ctx) |
| 94 | .await?; |
| 95 | } else if self.queries_path.to_str().unwrap().ends_with("join.sql") { |
| 96 | let join_paths: Vec<&str> = self.join_paths.split(',').collect(); |
| 97 | let table_name: Vec<&str> = vec!["x", "small", "medium", "large"]; |
| 98 | for (i, path) in join_paths.iter().enumerate() { |
| 99 | self.register_data(table_name[i], path, &ctx).await?; |
| 100 | } |
| 101 | } else if self.queries_path.to_str().unwrap().ends_with("window.sql") { |
| 102 | // Only register the 'large' table in h2o-join dataset |
| 103 | let h2o_join_large_path = self.join_paths.split(',').nth(3).unwrap(); |
| 104 | self.register_data("large", h2o_join_large_path, &ctx) |
| 105 | .await?; |
| 106 | } else { |
| 107 | return internal_err!("Invalid query file path"); |
| 108 | } |
| 109 | |
| 110 | let iterations = self.common.iterations; |
| 111 | let mut benchmark_run = BenchmarkRun::new(); |
| 112 | for query_id in query_range { |
| 113 | benchmark_run.start_new_case(&format!("Query {query_id}")); |
| 114 | let sql = queries.get_query(query_id)?; |
| 115 | println!("Q{query_id}: {sql}"); |
| 116 | |
| 117 | let mut millis = Vec::with_capacity(iterations); |
| 118 | for i in 1..=iterations { |
| 119 | let start = Instant::now(); |
| 120 | let results = ctx.sql(sql).await?.collect().await?; |
| 121 | let elapsed = start.elapsed(); |
| 122 | let ms = elapsed.as_secs_f64() * 1000.0; |
| 123 | millis.push(ms); |
| 124 | let row_count: usize = results.iter().map(|b| b.num_rows()).sum(); |
| 125 | println!( |
| 126 | "Query {query_id} iteration {i} took {ms:.1} ms and returned {row_count} rows" |
| 127 | ); |
| 128 | benchmark_run.write_iter(elapsed, row_count); |
| 129 | } |
| 130 | let avg = millis.iter().sum::<f64>() / millis.len() as f64; |
| 131 | println!("Query {query_id} avg time: {avg:.2} ms"); |
| 132 | |
| 133 | // Print memory usage stats using mimalloc (only when compiled with --features mimalloc_extended) |
| 134 | print_memory_stats(); |
| 135 |
nothing calls this directly
no test coverage detected