MCPcopy Create free account
hub / github.com/apache/datafusion / benchmark_query

Method benchmark_query

benchmarks/src/bin/external_aggr.rs:185–240  ·  view source on GitHub ↗

Benchmark query `query_id` in `AGGR_QUERIES`

(
        &self,
        query_id: usize,
        mem_limit: u64,
        mem_pool_type: &str,
    )

Source from the content-addressed store, hash-verified

183
184 /// Benchmark query `query_id` in `AGGR_QUERIES`
185 async fn benchmark_query(
186 &self,
187 query_id: usize,
188 mem_limit: u64,
189 mem_pool_type: &str,
190 ) -> Result<Vec<QueryResult>> {
191 let query_name =
192 format!("Q{query_id}({})", human_readable_size(mem_limit as usize));
193 let config = self.common.config()?;
194 let memory_pool: Arc<dyn MemoryPool> = match mem_pool_type {
195 "fair" => Arc::new(FairSpillPool::new(mem_limit as usize)),
196 "greedy" => Arc::new(GreedyMemoryPool::new(mem_limit as usize)),
197 _ => {
198 return exec_err!("Invalid memory pool type: {}", mem_pool_type);
199 }
200 };
201 let runtime_env = RuntimeEnvBuilder::new()
202 .with_memory_pool(memory_pool)
203 .build_arc()?;
204 let state = SessionStateBuilder::new()
205 .with_config(config)
206 .with_runtime_env(runtime_env)
207 .with_default_features()
208 .build();
209 let ctx = SessionContext::from(state);
210
211 // register tables
212 self.register_tables(&ctx).await?;
213
214 let mut millis = vec![];
215 // run benchmark
216 let mut query_results = vec![];
217 for i in 0..self.iterations() {
218 let start = Instant::now();
219
220 let query_idx = query_id - 1; // 1-indexed -> 0-indexed
221 let sql = Self::AGGR_QUERIES[query_idx];
222
223 let result = self.execute_query(&ctx, sql).await?;
224
225 let elapsed = start.elapsed(); //.as_secs_f64() * 1000.0;
226 let ms = elapsed.as_secs_f64() * 1000.0;
227 millis.push(ms);
228
229 let row_count = result.iter().map(|b| b.num_rows()).sum();
230 println!(
231 "{query_name} iteration {i} took {ms:.1} ms and returned {row_count} rows"
232 );
233 query_results.push(QueryResult { elapsed, row_count });
234 }
235
236 let avg = millis.iter().sum::<f64>() / millis.len() as f64;
237 println!("{query_name} avg time: {avg:.2} ms");
238
239 Ok(query_results)
240 }
241
242 async fn register_tables(&self, ctx: &SessionContext) -> Result<()> {

Callers 1

runMethod · 0.45

Calls 15

newFunction · 0.85
build_arcMethod · 0.80
with_default_featuresMethod · 0.80
sumMethod · 0.80
configMethod · 0.45
with_memory_poolMethod · 0.45
buildMethod · 0.45
with_runtime_envMethod · 0.45
with_configMethod · 0.45
register_tablesMethod · 0.45
iterationsMethod · 0.45
execute_queryMethod · 0.45

Tested by

no test coverage detected