mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Add group name in task metrics (#10196)
* SpawnNamed: add new trait methods Signed-off-by: Andrei Sandu <sandu.andrei@gmail.com> * Implement new methods Signed-off-by: Andrei Sandu <sandu.andrei@gmail.com> * cargo fmt Signed-off-by: Andrei Sandu <sandu.andrei@gmail.com> * SpawnNamed: add new trait methods Signed-off-by: Andrei Sandu <sandu.andrei@gmail.com> * Implement new methods Signed-off-by: Andrei Sandu <sandu.andrei@gmail.com> * cargo fmt Signed-off-by: Andrei Sandu <sandu.andrei@gmail.com> * New approach - spaw() group param Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Update traits: SpawnNamed and SpawnNamed Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Update TaskManager tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Update test TaskExecutor Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix typo Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * grunt work: fix spawn() calls Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cargo fmt Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * remove old code Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cargo fmt - the right version Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Implement review feedback - use Option group name in SpawnNamed methods - switch to kebab case - implement default group name - add group name to some tasks Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
@@ -152,10 +152,20 @@ impl Default for TaskExecutor {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl crate::traits::SpawnNamed for TaskExecutor {
|
||||
fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
_name: &'static str,
|
||||
_group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
self.0.spawn_ok(future);
|
||||
}
|
||||
fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
fn spawn(
|
||||
&self,
|
||||
_name: &'static str,
|
||||
_group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
self.0.spawn_ok(future);
|
||||
}
|
||||
}
|
||||
@@ -165,11 +175,17 @@ impl crate::traits::SpawnEssentialNamed for TaskExecutor {
|
||||
fn spawn_essential_blocking(
|
||||
&self,
|
||||
_: &'static str,
|
||||
_: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
self.0.spawn_ok(future);
|
||||
}
|
||||
fn spawn_essential(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
fn spawn_essential(
|
||||
&self,
|
||||
_: &'static str,
|
||||
_: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
self.0.spawn_ok(future);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,58 +190,91 @@ sp_externalities::decl_extension! {
|
||||
pub struct RuntimeSpawnExt(Box<dyn RuntimeSpawn>);
|
||||
}
|
||||
|
||||
/// Something that can spawn tasks (blocking and non-blocking) with an assigned name.
|
||||
/// Something that can spawn tasks (blocking and non-blocking) with an assigned name
|
||||
/// and optional group.
|
||||
#[dyn_clonable::clonable]
|
||||
pub trait SpawnNamed: Clone + Send + Sync {
|
||||
/// Spawn the given blocking future.
|
||||
///
|
||||
/// The given `name` is used to identify the future in tracing.
|
||||
fn spawn_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>);
|
||||
/// The given `group` and `name` is used to identify the future in tracing.
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
);
|
||||
/// Spawn the given non-blocking future.
|
||||
///
|
||||
/// The given `name` is used to identify the future in tracing.
|
||||
fn spawn(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>);
|
||||
/// The given `group` and `name` is used to identify the future in tracing.
|
||||
fn spawn(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
);
|
||||
}
|
||||
|
||||
impl SpawnNamed for Box<dyn SpawnNamed> {
|
||||
fn spawn_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
(**self).spawn_blocking(name, future)
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
(**self).spawn_blocking(name, group, future)
|
||||
}
|
||||
|
||||
fn spawn(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
(**self).spawn(name, future)
|
||||
fn spawn(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
(**self).spawn(name, group, future)
|
||||
}
|
||||
}
|
||||
|
||||
/// Something that can spawn essential tasks (blocking and non-blocking) with an assigned name.
|
||||
/// Something that can spawn essential tasks (blocking and non-blocking) with an assigned name
|
||||
/// and optional group.
|
||||
///
|
||||
/// Essential tasks are special tasks that should take down the node when they end.
|
||||
#[dyn_clonable::clonable]
|
||||
pub trait SpawnEssentialNamed: Clone + Send + Sync {
|
||||
/// Spawn the given blocking future.
|
||||
///
|
||||
/// The given `name` is used to identify the future in tracing.
|
||||
/// The given `group` and `name` is used to identify the future in tracing.
|
||||
fn spawn_essential_blocking(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
);
|
||||
/// Spawn the given non-blocking future.
|
||||
///
|
||||
/// The given `name` is used to identify the future in tracing.
|
||||
fn spawn_essential(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>);
|
||||
/// The given `group` and `name` is used to identify the future in tracing.
|
||||
fn spawn_essential(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
);
|
||||
}
|
||||
|
||||
impl SpawnEssentialNamed for Box<dyn SpawnEssentialNamed> {
|
||||
fn spawn_essential_blocking(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
(**self).spawn_essential_blocking(name, future)
|
||||
(**self).spawn_essential_blocking(name, group, future)
|
||||
}
|
||||
|
||||
fn spawn_essential(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
(**self).spawn_essential(name, future)
|
||||
fn spawn_essential(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
(**self).spawn_essential(name, group, future)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ impl BatchVerifier {
|
||||
|
||||
self.scheduler.spawn(
|
||||
name,
|
||||
None,
|
||||
async move {
|
||||
if !f() {
|
||||
invalid_clone.store(true, AtomicOrdering::Relaxed);
|
||||
@@ -177,7 +178,8 @@ impl BatchVerifier {
|
||||
if pending.len() > 0 {
|
||||
let (sender, receiver) = std::sync::mpsc::channel();
|
||||
self.scheduler.spawn(
|
||||
"substrate_batch_verify_join",
|
||||
"substrate-batch-verify-join",
|
||||
None,
|
||||
async move {
|
||||
futures::future::join_all(pending).await;
|
||||
sender.send(()).expect(
|
||||
|
||||
@@ -95,6 +95,7 @@ mod inner {
|
||||
let extra_scheduler = scheduler.clone();
|
||||
scheduler.spawn(
|
||||
"parallel-runtime-spawn",
|
||||
Some("substrate-runtime"),
|
||||
Box::pin(async move {
|
||||
let result = match crate::new_async_externalities(extra_scheduler) {
|
||||
Ok(mut ext) => {
|
||||
|
||||
Reference in New Issue
Block a user