Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.lock

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

46 changes: 13 additions & 33 deletions rs/p2p/artifact_manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,27 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
# Keep sorted.
"//rs/interfaces",
"//rs/limits",
"//rs/monitoring/metrics",
"//rs/p2p/consensus_manager",
"//rs/types/types",
"@crate_index//:prometheus",
"@crate_index//:tokio",
"@crate_index//:tracing",
]

MACRO_DEPENDENCIES = []

DEV_DEPENDENCIES = [
# Keep sorted.
"//rs/artifact_pool",
"//rs/config",
"//rs/protobuf",
"//rs/test_utilities",
"@crate_index//:assert_matches",
]

MACRO_DEV_DEPENDENCIES = []

ALIASES = {}

rust_library(
name = "artifact_manager",
srcs = glob(["src/**"]),
aliases = ALIASES,
crate_name = "ic_artifact_manager",
proc_macro_deps = MACRO_DEPENDENCIES,
version = "0.9.0",
deps = DEPENDENCIES,
deps = [
# Keep sorted.
"//rs/interfaces",
"//rs/limits",
"//rs/monitoring/metrics",
"//rs/p2p/consensus_manager",
"//rs/types/types",
"@crate_index//:prometheus",
"@crate_index//:static_assertions",
"@crate_index//:tokio",
"@crate_index//:tracing",
],
)

rust_test(
name = "artifact_manager_test",
aliases = ALIASES,
crate = ":artifact_manager",
proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
deps = DEPENDENCIES + DEV_DEPENDENCIES,
deps = [],
)
6 changes: 1 addition & 5 deletions rs/p2p/artifact_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ ic-limits = { path = "../../limits" }
ic-metrics = { path = "../../monitoring/metrics" }
ic-types = { path = "../../types/types" }
prometheus = { workspace = true }
static_assertions = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
ic-artifact-pool = { path = "../../artifact_pool" }
ic-config = { path = "../../config" }
ic-protobuf = { path = "../../protobuf" }
ic-test-utilities = { path = "../../test_utilities" }
23 changes: 15 additions & 8 deletions rs/p2p/artifact_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use tokio::{
};
use tracing::instrument;

/// How long to wait between consecutive `on_state_change` calls.
const ARTIFACT_MANAGER_TIMER_DURATION: Duration = Duration::from_millis(200);

/// Metrics for a client artifact processor.
struct ArtifactProcessorMetrics {
/// The processing time histogram.
Expand All @@ -40,6 +43,16 @@ struct ArtifactProcessorMetrics {
impl ArtifactProcessorMetrics {
/// The constructor creates a `ArtifactProcessorMetrics` instance.
fn new(metrics_registry: MetricsRegistry, client: String) -> Self {
const PROCESSING_INTERVAL_BUCKETS: [f64; 10] =
[0.0, 0.01, 0.02, 0.05, 0.1, 0.15, 0.2, 0.3, 0.5, 1.0];

// This is a bit hacky but we have this static assertion to make sure that there is a bucket
// of size `ARTIFACT_MANAGER_TIMER_DURATION` in `PROCESSING_INTERVAL_BUCKETS`.
static_assertions::const_assert_eq!(
PROCESSING_INTERVAL_BUCKETS[6],
ARTIFACT_MANAGER_TIMER_DURATION.as_secs_f64(),
);

let const_labels = labels! {"client".to_string() => client.to_string()};
let processing_time = metrics_registry.register(
Histogram::with_opts(histogram_opts!(
Expand All @@ -57,10 +70,7 @@ impl ArtifactProcessorMetrics {
Histogram::with_opts(histogram_opts!(
"artifact_manager_client_processing_interval_seconds",
"Duration between Artifact manager client processing, in seconds",
vec![
0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1.0, 1.2, 1.5, 2.0, 2.2, 2.5, 5.0, 8.0,
10.0, 15.0, 20.0, 50.0,
],
PROCESSING_INTERVAL_BUCKETS.to_vec(),
const_labels.clone()
))
.unwrap(),
Expand Down Expand Up @@ -201,7 +211,7 @@ fn process_messages<Artifact: IdentifiableArtifact + 'static>(
let recv_timeout = if last_on_state_change_result {
Duration::from_millis(0)
} else {
Duration::from_millis(ARTIFACT_MANAGER_TIMER_DURATION_MSEC)
ARTIFACT_MANAGER_TIMER_DURATION
};

let batched_artifact_events =
Expand All @@ -223,9 +233,6 @@ fn process_messages<Artifact: IdentifiableArtifact + 'static>(
}
}

/// Periodic duration of `PollEvent` in milliseconds.
const ARTIFACT_MANAGER_TIMER_DURATION_MSEC: u64 = 200;

pub fn create_ingress_handlers<
PoolIngress: MutablePool<SignedIngress> + Send + Sync + ValidatedPoolReader<SignedIngress> + 'static,
>(
Expand Down
Loading