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

add basic metrics of multilevel task queue #27

Merged
merged 6 commits into from
Feb 7, 2020
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ parking_lot_core = "0.7"
crossbeam-deque = "0.7"
dashmap = "1.2.0"
rand = "0.7"
lazy_static = "1"

[dependencies.prometheus]
# FIXME: Use crates-io version when rust-prometheus 0.8 is released
git = "https://github.com/tikv/rust-prometheus.git"
rev = "d919ccd35976b9b84b8d03c07138c1cc05a36087"

[dev-dependencies]
criterion = "0.3"
Expand All @@ -38,4 +44,4 @@ name = "ping_pong"
harness = false

[profile.bench]
codegen-units = 1
codegen-units = 1
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! Yatp is a thread pool that tries to be adaptive, responsive and generic.

pub mod metrics;
pub mod pool;
pub mod queue;
pub mod task;
Expand Down
47 changes: 47 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

//! Metrics of the thread pool.

use lazy_static::lazy_static;
use prometheus::*;
use std::sync::Mutex;

lazy_static! {
/// Elapsed time of each level in the multilevel task queue.
pub static ref MULTILEVEL_LEVEL_ELAPSED: IntCounterVec = IntCounterVec::new(
new_opts(
"multilevel_level_elapsed",
"elapsed time of each level in the multilevel task queue"
),
&["name", "level"]
)
.unwrap();

/// The chance that a level 0 task is scheduled to run.
pub static ref MULTILEVEL_LEVEL0_CHANCE: GaugeVec = GaugeVec::new(
new_opts(
"multilevel_level0_chance",
"the chance that a level 0 task is scheduled to run"
),
&["name"]
)
.unwrap();

static ref NAMESPACE: Mutex<Option<String>> = Mutex::new(None);
}

/// Sets the namespace used in the metrics. This function should be called before
/// the metrics are used or any thread pool is created.
///
/// The namespace is missing by default.
pub fn set_namespace(s: Option<impl Into<String>>) {
*NAMESPACE.lock().unwrap() = s.map(Into::into)
}

fn new_opts(name: &str, help: &str) -> Opts {
let mut opts = Opts::new(name, help);
if let Some(ref namespace) = *NAMESPACE.lock().unwrap() {
opts = opts.namespace(namespace);
}
opts
}
Loading