Skip to content

Commit 3f58992

Browse files
committed
chore(cubestore): Upgrade DF: Add data frame serialization time metrics
1 parent 103fb9c commit 3f58992

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

rust/cubestore/cubestore/src/app_metrics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ pub static DATA_QUERY_CREATE_ROUTER_PHYSICAL_PLAN_US: Histogram =
5353
pub static DATA_QUERY_CREATE_WORKER_PHYSICAL_PLAN_US: Histogram =
5454
metrics::histogram("cs.sql.query.data.planning.worker_plan.us");
5555

56+
pub static SQL_DATA_FRAME_SERIALIZATION_TIME_US: Histogram =
57+
metrics::histogram("cs.sql.data_frame_serialization.us");
58+
pub static HTTP_MESSAGE_DATA_FRAME_SERIALIZATION_TIME_US: Histogram =
59+
metrics::histogram("cs.http.data_frame_serialization.us");
60+
5661
/// Incoming SQL queries that only read metadata or do trivial computations.
5762
pub static META_QUERIES: Counter = metrics::counter("cs.sql.query.meta");
5863
pub static META_QUERY_TIME_MS: Histogram = metrics::histogram("cs.sql.query.meta.ms");

rust/cubestore/cubestore/src/http/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::sql::{InlineTable, InlineTables, SqlQueryContext, SqlService};
1010
use crate::store::DataFrame;
1111
use crate::table::{Row, TableValue};
1212
use crate::util::WorkerLoop;
13-
use crate::CubeError;
13+
use crate::{app_metrics, CubeError};
1414
use async_std::fs::File;
1515
use cubeshared::codegen::{
1616
root_as_http_message, HttpColumnValue, HttpColumnValueArgs, HttpError, HttpErrorArgs,
@@ -600,6 +600,7 @@ pub enum HttpCommand {
600600
impl HttpMessage {
601601
pub fn bytes(&self) -> Vec<u8> {
602602
let mut builder = FlatBufferBuilder::with_capacity(1024);
603+
let mut data_frame_serialization_start = None::<SystemTime>;
603604
let args = HttpMessageArgs {
604605
message_id: self.message_id,
605606
command_type: match self.command {
@@ -645,6 +646,7 @@ impl HttpMessage {
645646
)
646647
}
647648
HttpCommand::ResultSet { data_frame } => {
649+
data_frame_serialization_start = Some(SystemTime::now());
648650
let columns_vec =
649651
HttpMessage::build_columns(&mut builder, data_frame.get_columns());
650652
let rows = HttpMessage::build_rows(&mut builder, data_frame.clone());
@@ -668,7 +670,16 @@ impl HttpMessage {
668670
};
669671
let message = cubeshared::codegen::HttpMessage::create(&mut builder, &args);
670672
builder.finish(message, None);
671-
builder.finished_data().to_vec() // TODO copy
673+
let result = builder.finished_data().to_vec(); // TODO copy
674+
if let Some(data_frame_serialization_start) = data_frame_serialization_start {
675+
app_metrics::HTTP_MESSAGE_DATA_FRAME_SERIALIZATION_TIME_US.report(
676+
data_frame_serialization_start
677+
.elapsed()
678+
.unwrap_or_else(|_| Duration::ZERO)
679+
.as_micros() as i64,
680+
);
681+
}
682+
result
672683
}
673684

674685
pub fn should_close_connection(&self) -> bool {

rust/cubestore/cubestore/src/mysql/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::config::processing_loop::ProcessingLoop;
22
use crate::sql::{InlineTables, SqlQueryContext, SqlService};
33
use crate::table::TableValue;
44
use crate::util::time_span::warn_long;
5-
use crate::{metastore, CubeError};
5+
use crate::{app_metrics, metastore, CubeError};
66
use async_trait::async_trait;
77
use datafusion::cube_ext;
88
use hex::ToHex;
@@ -78,6 +78,9 @@ impl<W: io::Write + Send> AsyncMysqlShim<W> for Backend {
7878
}
7979
let _s = warn_long("sending query results", Duration::from_millis(100));
8080
let data_frame = res.unwrap();
81+
82+
let data_frame_serialization_start_time = SystemTime::now();
83+
8184
let columns = data_frame
8285
.get_columns()
8386
.iter()
@@ -133,7 +136,20 @@ impl<W: io::Write + Send> AsyncMysqlShim<W> for Backend {
133136
rw.end_row()?;
134137
}
135138
rw.finish()?;
136-
if start.elapsed().unwrap().as_millis() > 200 && query.to_lowercase().starts_with("select")
139+
140+
let end_time = SystemTime::now();
141+
app_metrics::SQL_DATA_FRAME_SERIALIZATION_TIME_US.report(
142+
end_time
143+
.duration_since(data_frame_serialization_start_time)
144+
.unwrap_or_default()
145+
.as_micros() as i64,
146+
);
147+
if end_time
148+
.duration_since(start)
149+
.unwrap_or_default()
150+
.as_millis()
151+
> 200
152+
&& query.to_lowercase().starts_with("select")
137153
{
138154
warn!(
139155
"Slow Query SQL ({:?}):\n{}",

0 commit comments

Comments
 (0)