Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracing): add minitrace to RisingLight #550

Merged
merged 6 commits into from
Mar 14, 2022

Conversation

WindowsXp-Beta
Copy link
Contributor

@WindowsXp-Beta WindowsXp-Beta commented Mar 7, 2022

close #368
Signed-off-by: Xinpeng Wei xinpeng@singularity-data.com

@skyzh
Copy link
Member

skyzh commented Mar 7, 2022

After some offline discussions, I think it's better to define a trace_executor(stream: impl Stream) -> impl Stream function to trace the runtime status of each executor.

@skyzh skyzh changed the title feat(tracing): add minitrace to RL(#368) feat(tracing): add minitrace to RisingLight Mar 7, 2022
@skyzh skyzh marked this pull request as draft March 8, 2022 06:05
@arkbriar
Copy link
Contributor

arkbriar commented Mar 9, 2022

I think current implementation is too intrusive in that it changes the signature of the entire executor builder. IMO it's better to hide the trace works outside the core executors and do it in a unified way (not each time we add a new executor), which can be achieved by proxying the visitor. Also we can attach any common modifiers here according to the build options, such as cancellable (since it's only necessary for those io aware executors, I don't recommend to do that).

diff --git a/src/executor/mod.rs b/src/executor/mod.rs
index cf93b53..e5040c3 100644
--- a/src/executor/mod.rs
+++ b/src/executor/mod.rs
@@ -207,6 +207,11 @@ impl ExecutorExt for BoxedExecutor {
 }

 impl PlanVisitor<BoxedExecutor> for ExecutorBuilder {
+    fn visit(&mut self, plan: PlanRef) -> Option<BoxedExecutor> {
+        println!("before");
+        // `trace` is a modifier here that do the trace.
+        self.visit_inner(plan).trace()
+    }
+
     fn visit_dummy(&mut self, _plan: &Dummy) -> Option<BoxedExecutor> {
         Some(DummyScanExecutor.execute())
     }
diff --git a/src/optimizer/plan_visitor.rs b/src/optimizer/plan_visitor.rs
index 6f1d82d..ac173f7 100644
--- a/src/optimizer/plan_visitor.rs
+++ b/src/optimizer/plan_visitor.rs
@@ -11,7 +11,11 @@ macro_rules! def_visitor {
     /// The visitor for plan nodes. visit all children and return the ret value of the left most child.
     pub trait PlanVisitor<R> {
     paste! {
-      fn visit(&mut self, plan: PlanRef) -> Option<R>{
+      fn visit(&mut self, plan: PlanRef) -> Option<R> {
+        self.visit_inner(plan)
+      }
+
+      fn visit_inner(&mut self, plan: PlanRef) -> Option<R> {
         match plan.node_type() {
         $(
           crate::optimizer::plan_nodes::PlanNodeType::$node => self.[<visit_ $node:snake>](plan.downcast_ref::<$node>().unwrap()),

BTW, minitrace is not suitable for tracing under such execution model as it does not support the async enter of the span tree unless we modify the executor's interface.

@skyzh
Copy link
Member

skyzh commented Mar 9, 2022

BTW, minitrace is not suitable for tracing under such execution model as it does not support the async enter of the span tree unless we modify the executor's interface.

I think it can. We propose to add a trace_stream function, which traces every .next call of the executor. minitrace supports async interface, see https://docs.rs/minitrace/latest/minitrace/future/index.html for more information.

@arkbriar
Copy link
Contributor

arkbriar commented Mar 9, 2022

I think it can. We propose to add a trace_stream function, which traces every .next call of the executor. minitrace supports async interface, see https://docs.rs/minitrace/latest/minitrace/future/index.html for more information.

I see.

Signed-off-by: Xinpeng Wei <xinpeng@singularity-data.com>
Xinpeng Wei added 2 commits March 10, 2022 16:42
Signed-off-by: Xinpeng Wei <xinpeng@singularity-data.com>
…#368)

Signed-off-by: Xinpeng Wei <xinpeng@singularity-data.com>
Copy link
Member

@skyzh skyzh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM. Any ideas from cc @zhongzc @breeswish? Thanks!

src/db.rs Outdated
for chunk in &output {
debug!("output:\n{}", chunk);
}
if !column_names.is_empty() && !output.is_empty() {
output[0].set_header(column_names);
}
outputs.push(Chunk::new(output));

let records: Vec<SpanRecord> = block_on(collector.collect());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use .await instead of block_on.

for chunk in &output {
debug!("output:\n{}", chunk);
}
if !column_names.is_empty() && !output.is_empty() {
output[0].set_header(column_names);
}
outputs.push(Chunk::new(output));

let records: Vec<SpanRecord> = block_on(collector.collect());
println!("{records:#?}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it an optional feature? Either using https://doc.rust-lang.org/cargo/reference/features.html and #[cfg(feature = enable_tracing)], or use cli arg to specify whether to enable it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha

@skyzh skyzh marked this pull request as ready for review March 11, 2022 11:10
Xinpeng Wei added 2 commits March 11, 2022 20:34
Signed-off-by: Xinpeng Wei <xinpeng@singularity-data.com>
Signed-off-by: Xinpeng Wei <xinpeng@singularity-data.com>
Copy link
Member

@skyzh skyzh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, good work!

@skyzh skyzh enabled auto-merge (squash) March 14, 2022 10:37
@skyzh skyzh merged commit 445cdd1 into risinglightdb:main Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tracing: add minitrace to RisingLight
3 participants