Skip to content

Commit c34c735

Browse files
committed
chore: refine benchmark profile details
1 parent 8219fbd commit c34c735

1 file changed

Lines changed: 19 additions & 63 deletions

File tree

benchmark/src/bin/benchmark_cloud.rs

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,15 @@ struct ServerStatsRecord {
8585
spill_bytes: usize,
8686
}
8787

88-
#[derive(Serialize)]
89-
struct QueryExecutionRecord {
90-
node: String,
91-
query_id: String,
92-
process_rows: u64,
93-
process_time_in_micros: u64,
94-
}
95-
9688
#[derive(Serialize)]
9789
struct SystemHistoryRecord {
9890
#[serde(skip_serializing_if = "Option::is_none")]
9991
query_history: Option<serde_json::Value>,
10092
#[serde(skip_serializing_if = "Vec::is_empty")]
10193
profile_history: Vec<serde_json::Value>,
10294
#[serde(skip_serializing_if = "Option::is_none")]
95+
profile_statistics_desc: Option<serde_json::Value>,
96+
#[serde(skip_serializing_if = "Option::is_none")]
10397
error: Option<String>,
10498
}
10599

@@ -116,8 +110,6 @@ struct QueryAttempt {
116110
server_stats: Option<ServerStatsRecord>,
117111
#[serde(skip_serializing_if = "Vec::is_empty")]
118112
stats_samples: Vec<ServerStatsRecord>,
119-
#[serde(skip_serializing_if = "Vec::is_empty")]
120-
query_execution: Vec<QueryExecutionRecord>,
121113
#[serde(skip_serializing_if = "Option::is_none")]
122114
system_history: Option<SystemHistoryRecord>,
123115
#[serde(skip_serializing_if = "Option::is_none")]
@@ -352,13 +344,6 @@ async fn run_query_attempt(conn: &Connection, sql: &str, attempt: usize) -> Quer
352344

353345
let client_wall_ms = start.elapsed().as_millis();
354346
let query_id = conn.last_query_id();
355-
let query_execution = if let Some(query_id) = &query_id {
356-
collect_query_execution(conn, query_id)
357-
.await
358-
.unwrap_or_default()
359-
} else {
360-
Vec::new()
361-
};
362347
let elapsed_seconds = final_stats
363348
.as_ref()
364349
.map(|stats| round3(stats.running_time_ms / 1000.0))
@@ -372,52 +357,15 @@ async fn run_query_attempt(conn: &Connection, sql: &str, attempt: usize) -> Quer
372357
query_id,
373358
server_stats: final_stats,
374359
stats_samples,
375-
query_execution,
376360
system_history: None,
377361
error,
378362
}
379363
}
380364

381-
async fn collect_query_execution(
382-
conn: &Connection,
383-
query_id: &str,
384-
) -> Result<Vec<QueryExecutionRecord>> {
385-
let query_id_literal = quote_literal(query_id);
386-
let sql = format!(
387-
"select node, query_id, process_rows, process_time_in_micros \
388-
from system.query_execution where query_id = '{query_id_literal}' order by node"
389-
);
390-
391-
for delay in [0_u64, 100, 500, 1000, 2000] {
392-
if delay > 0 {
393-
tokio::time::sleep(Duration::from_millis(delay)).await;
394-
}
395-
let rows = conn.query_all(&sql).await?;
396-
if !rows.is_empty() {
397-
let mut records = Vec::with_capacity(rows.len());
398-
for row in rows {
399-
let (node, query_id, process_rows, process_time_in_micros): (
400-
String,
401-
String,
402-
u64,
403-
u64,
404-
) = row.try_into().map_err(|err: String| anyhow!(err))?;
405-
records.push(QueryExecutionRecord {
406-
node,
407-
query_id,
408-
process_rows,
409-
process_time_in_micros,
410-
});
411-
}
412-
return Ok(records);
413-
}
414-
}
415-
Ok(Vec::new())
416-
}
417-
418365
async fn collect_system_history(conn: &Connection, query_id: &str) -> SystemHistoryRecord {
419366
let mut query_history = None;
420367
let mut profile_history = Vec::new();
368+
let mut profile_statistics_desc = None;
421369
let mut error = None;
422370

423371
for delay in [0_u64, 500, 1000, 2000] {
@@ -435,9 +383,10 @@ async fn collect_system_history(conn: &Connection, query_id: &str) -> SystemHist
435383
}
436384

437385
match collect_profile_history(conn, query_id).await {
438-
Ok(records) => {
386+
Ok((records, statistics_desc)) => {
439387
if !records.is_empty() {
440388
profile_history = records;
389+
profile_statistics_desc = statistics_desc;
441390
}
442391
}
443392
Err(err) => {
@@ -454,6 +403,7 @@ async fn collect_system_history(conn: &Connection, query_id: &str) -> SystemHist
454403
SystemHistoryRecord {
455404
query_history,
456405
profile_history,
406+
profile_statistics_desc,
457407
error,
458408
}
459409
}
@@ -506,6 +456,7 @@ fn history_error(error: String) -> SystemHistoryRecord {
506456
SystemHistoryRecord {
507457
query_history: None,
508458
profile_history: Vec::new(),
459+
profile_statistics_desc: None,
509460
error: Some(error),
510461
}
511462
}
@@ -597,16 +548,16 @@ async fn collect_query_history(
597548
async fn collect_profile_history(
598549
conn: &Connection,
599550
query_id: &str,
600-
) -> Result<Vec<serde_json::Value>> {
551+
) -> Result<(Vec<serde_json::Value>, Option<serde_json::Value>)> {
601552
let query_id_literal = quote_literal(query_id);
602553
let sql = format!(
603554
r#"
604555
SELECT to_string(object_construct(
605556
'timestamp', timestamp,
606557
'query_id', query_id,
607-
'profiles', profiles,
608-
'statistics_desc', statistics_desc
609-
))
558+
'profiles', profiles
559+
)),
560+
to_string(statistics_desc)
610561
FROM system_history.profile_history
611562
WHERE query_id = '{query_id_literal}'
612563
ORDER BY timestamp
@@ -615,13 +566,19 @@ async fn collect_profile_history(
615566

616567
let rows = conn.query_all(&sql).await?;
617568
let mut records = Vec::with_capacity(rows.len());
569+
let mut statistics_desc = None;
618570
for row in rows {
619-
let (raw,): (Option<String>,) = row.try_into().map_err(|err: String| anyhow!(err))?;
571+
let (raw, statistics_desc_raw): (Option<String>, Option<String>) =
572+
row.try_into().map_err(|err: String| anyhow!(err))?;
620573
if let Some(raw) = raw {
621574
records.push(json_or_raw(&raw));
622575
}
576+
if statistics_desc.is_none() {
577+
statistics_desc = statistics_desc_raw.map(|raw| json_or_raw(&raw));
578+
}
623579
}
624-
Ok(records)
580+
581+
Ok((records, statistics_desc))
625582
}
626583

627584
fn json_or_raw(raw: &str) -> serde_json::Value {
@@ -724,7 +681,6 @@ async fn main() -> Result<()> {
724681
timing_source: "server_stats.running_time_ms".to_string(),
725682
detail_sources: vec![
726683
"databend-driver query_iter_ext".to_string(),
727-
"system.query_execution".to_string(),
728684
"system_history.query_history".to_string(),
729685
"system_history.profile_history".to_string(),
730686
],

0 commit comments

Comments
 (0)