Skip to content

Commit

Permalink
refactor: set name for all runtime worker threads. (#17084)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun authored Dec 24, 2024
1 parent b0bb940 commit ff6cb3e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 45 deletions.
35 changes: 18 additions & 17 deletions src/common/base/src/runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,25 @@ impl Runtime {

let n = name.clone();
// Block the runtime to shutdown.
let join_handler = Thread::spawn(move || {
let _ = runtime.block_on(recv_stop);
info!(
"Runtime({:?}) received shutdown signal, start to shut down",
n
);

match !cfg!(debug_assertions) {
true => false,
false => {
let instant = Instant::now();
// We wait up to 3 seconds to complete the runtime shutdown.
runtime.shutdown_timeout(Duration::from_secs(3));

instant.elapsed() >= Duration::from_secs(3)
let join_handler =
Thread::named_spawn(n.as_ref().map(|n| format!("wait-to-drop-{n}")), move || {
let _ = runtime.block_on(recv_stop);
info!(
"Runtime({:?}) received shutdown signal, start to shut down",
n
);

match !cfg!(debug_assertions) {
true => false,
false => {
let instant = Instant::now();
// We wait up to 3 seconds to complete the runtime shutdown.
runtime.shutdown_timeout(Duration::from_secs(3));

instant.elapsed() >= Duration::from_secs(3)
}
}
}
});
});

Ok(Runtime {
handle,
Expand Down
24 changes: 13 additions & 11 deletions src/query/service/src/pipelines/builders/builder_compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ impl PipelineBuilder {
let column_ids = compact_block.column_ids.clone();
self.main_pipeline.set_on_init(move || {
let ctx = query_ctx.clone();
let partitions = Runtime::with_worker_threads(2, None)?.block_on(async move {
let partitions = BlockCompactMutator::build_compact_tasks(
ctx.clone(),
column_ids.clone(),
cluster_key_id,
thresholds,
lazy_parts,
)
.await?;
let partitions =
Runtime::with_worker_threads(2, Some("build_compact_tasks".to_string()))?
.block_on(async move {
let partitions = BlockCompactMutator::build_compact_tasks(
ctx.clone(),
column_ids.clone(),
cluster_key_id,
thresholds,
lazy_parts,
)
.await?;

Result::<_>::Ok(partitions)
})?;
Result::<_>::Ok(partitions)
})?;

let partitions = Partitions::create(PartitionsShuffleKind::Mod, partitions);
query_ctx.set_partitions(partitions)?;
Expand Down
29 changes: 15 additions & 14 deletions src/query/service/src/pipelines/builders/builder_mutation_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,21 @@ impl PipelineBuilder {
segment_locations,
block_count: None,
};
Runtime::with_worker_threads(2, None)?.block_on(async move {
let (partitions, _) = table_clone
.do_mutation_block_pruning(
ctx_clone,
filters_clone,
projection,
prune_ctx,
true,
true,
)
.await?;
ctx.set_partitions(partitions)?;
Ok(())
})?;
Runtime::with_worker_threads(2, Some("do_mutation_block_pruning".to_string()))?
.block_on(async move {
let (partitions, _) = table_clone
.do_mutation_block_pruning(
ctx_clone,
filters_clone,
projection,
prune_ctx,
true,
true,
)
.await?;
ctx.set_partitions(partitions)?;
Ok(())
})?;
} else {
self.ctx
.set_partitions(mutation_source.partitions.clone())?;
Expand Down
3 changes: 2 additions & 1 deletion src/query/storages/fuse/src/operations/read_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ impl FuseTable {
// We cannot use the runtime associated with the query to avoid increasing its lifetime.
GlobalIORuntime::instance().spawn(async move {
// avoid block global io runtime
let runtime = Runtime::with_worker_threads(2, None)?;
let runtime =
Runtime::with_worker_threads(2, Some("prune-snap-blk".to_string()))?;
let handler = runtime.spawn(async move {
match table
.prune_snapshot_blocks(
Expand Down
4 changes: 2 additions & 2 deletions src/query/storages/fuse/src/operations/read_partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl FuseTable {
// We cannot use the runtime associated with the query to avoid increasing its lifetime.
GlobalIORuntime::instance().spawn(async move {
// avoid block global io runtime
let runtime = Runtime::with_worker_threads(2, None)?;
let runtime = Runtime::with_worker_threads(2, Some("send-parts".to_string()))?;

let join_handler = runtime.spawn(async move {
for part in part.partitions {
Expand Down Expand Up @@ -241,7 +241,7 @@ impl FuseTable {
// We cannot use the runtime associated with the query to avoid increasing its lifetime.
GlobalIORuntime::instance().spawn(async move {
// avoid block global io runtime
let runtime = Runtime::with_worker_threads(2, None)?;
let runtime = Runtime::with_worker_threads(2, Some("prune-seg".to_string()))?;
let join_handler = runtime.spawn(async move {
let segment_pruned_result =
pruner.clone().segment_pruning(lazy_init_segments).await?;
Expand Down

0 comments on commit ff6cb3e

Please sign in to comment.