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(query): try support dump running async task stack #10830

Merged
merged 15 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
55 changes: 55 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ reqwest = { version = "0.11", default-features = false, features = [
# runtime
tokio = { version = "1.26.0", features = ["full"] }

# backtrace
async-backtrace = "0.2.2"

[profile.release]
debug = 1
lto = "thin"
Expand Down
1 change: 1 addition & 0 deletions src/binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ sharing-endpoint = { path = "../query/sharing-endpoint" }
# Crates.io dependencies
anyerror = { workspace = true }
anyhow = { workspace = true }
async-backtrace = { workspace = true }
clap = { workspace = true }
comfy-table = "6.1.3"
limits-rs = "0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/binaries/query/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() {
std::process::exit(cause.code() as i32);
}
Ok(rt) => {
if let Err(cause) = rt.block_on(main_entrypoint()) {
if let Err(cause) = rt.block_on(async_backtrace::location!().frame(main_entrypoint())) {
eprintln!("Databend Query start failure, cause: {:?}", cause);
std::process::exit(cause.code() as i32);
}
Expand Down
1 change: 1 addition & 0 deletions src/common/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ common-exception = { path = "../exception" }
# Github dependencies

# Crates.io dependencies
async-backtrace = "0.2.2"
async-channel = "1.7.1"
async-trait = "0.1.57"
bytesize = "1.1.0"
Expand Down
16 changes: 11 additions & 5 deletions src/common/base/src/runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ impl Runtime {
runtime_builder.thread_name(thread_name);
}
}

runtime_builder.thread_stack_size(5 * 1024 * 1024);
}

Self::create(None, mem_stat, &mut runtime_builder)
Expand All @@ -179,6 +181,8 @@ impl Runtime {
thread_name = Some(cur_thread_name.to_string());
}
}

runtime_builder.thread_stack_size(5 * 1024 * 1024);
}

if let Some(thread_name) = &thread_name {
Expand Down Expand Up @@ -255,10 +259,12 @@ impl Runtime {
let permit = semaphore.acquire_owned().await.map_err(|e| {
ErrorCode::Internal(format!("semaphore closed, acquire permit failure. {}", e))
})?;
let handler = self.handle.spawn(async move {
// take the ownership of the permit, (implicitly) drop it when task is done
fut(permit).await
});
let handler = self
.handle
.spawn(async_backtrace::location!().frame(async move {
// take the ownership of the permit, (implicitly) drop it when task is done
fut(permit).await
}));
handlers.push(handler)
}

Expand All @@ -273,7 +279,7 @@ impl TrySpawn for Runtime {
T: Future + Send + 'static,
T::Output: Send + 'static,
{
Ok(self.handle.spawn(task))
Ok(self.handle.spawn(async_backtrace::location!().frame(task)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/base/src/runtime/runtime_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ mod tests {
.unwrap();

rt.block_on(async {
let h = tokio::spawn(f);
let h = tokio::spawn(async_backtrace::location!().frame(f));
let res = h.await;
assert!(res.is_err(), "panicked");
});
Expand Down
2 changes: 2 additions & 0 deletions src/common/base/src/runtime/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ impl Thread {
name = Some(thread_name.to_string());
}
}

thread_builder = thread_builder.stack_size(5 * 1024 * 1024);
}

let mut mem_stat_name = String::from("UnnamedThread");
Expand Down
1 change: 1 addition & 0 deletions src/common/base/tests/it/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async fn test_shutdown_long_run_runtime() -> Result<()> {
}

static START_TIME: Lazy<Instant> = Lazy::new(Instant::now);

// println can more clearly know if they are parallel
async fn mock_get_page(i: usize) -> Vec<usize> {
let millis = Uniform::from(0..10).sample(&mut rand::thread_rng());
Expand Down
1 change: 1 addition & 0 deletions src/common/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ common-exception = { path = "../exception" }

# Crates.io dependencies
anyerror = { workspace = true }
async-backtrace = { workspace = true }
futures = "0.3.24"
poem = { version = "1", features = ["rustls"] }
serde = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions src/common/http/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ pub mod pprof;

#[cfg(feature = "memory-profiling")]
pub mod jeprof;
pub mod stack;

pub use home::PProfRequest;
Loading