Skip to content

Commit

Permalink
add static metrics for multilevel queue
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
  • Loading branch information
sticnarf committed Jan 6, 2020
1 parent 50f4037 commit 074f36e
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 123 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ parking_lot_core = "0.7"
crossbeam-deque = "0.7"
dashmap = "1.2.0"
rand = "0.7"
prometheus = "0.7"
lazy_static = "1"

[dev-dependencies]
criterion = "0.3"
Expand Down
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.
mod metrics;
pub mod pool;
pub mod queue;
pub mod task;
Expand Down
21 changes: 21 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use lazy_static::lazy_static;
use prometheus::*;

lazy_static! {
pub static ref MULTILEVEL_LEVEL_ELAPSED: IntCounterVec = IntCounterVec::new(
Opts::new(
"multilevel_level_elapsed",
"elapsed time of each level in the multilevel task queue"
),
&["name", "level"]
)
.unwrap();
pub static ref MULTILEVEL_LEVEL0_CHANCE: GaugeVec = GaugeVec::new(
Opts::new(
"multilevel_level0_chance",
"the chance that a level 0 task is scheduled to run"
),
&["name"]
)
.unwrap();
}
7 changes: 1 addition & 6 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::builder::{Builder, SchedConfig};
pub use self::runner::{CloneRunnerBuilder, Runner, RunnerBuilder};
pub use self::spawn::{build_spawn, Local, Remote};

use crate::queue::{QueueStatistics, TaskCell, WithExtras};
use crate::queue::{TaskCell, WithExtras};
use std::mem;
use std::sync::Mutex;
use std::thread::JoinHandle;
Expand Down Expand Up @@ -48,11 +48,6 @@ impl<T: TaskCell + Send> ThreadPool<T> {
pub fn remote(&self) -> &Remote<T> {
&self.remote
}

/// Gets the task queue statistics of the thread pool.
pub fn queue_statistics(&self) -> QueueStatistics {
self.remote.queue_statistics()
}
}

impl<T: TaskCell + Send> Drop for ThreadPool<T> {
Expand Down
11 changes: 1 addition & 10 deletions src/pool/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! tasks waiting to be handled.
use crate::pool::SchedConfig;
use crate::queue::{Extras, LocalQueue, Pop, QueueStatistics, TaskCell, TaskInjector, WithExtras};
use crate::queue::{Extras, LocalQueue, Pop, TaskCell, TaskInjector, WithExtras};
use parking_lot_core::{ParkResult, ParkToken, UnparkToken};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -131,10 +131,6 @@ impl<T: TaskCell + Send> QueueCore<T> {
fn default_extras(&self) -> Extras {
self.global_queue.default_extras()
}

pub fn queue_statistics(&self) -> QueueStatistics {
self.global_queue.statistics()
}
}

/// Submits tasks to associated thread pool.
Expand All @@ -156,11 +152,6 @@ impl<T: TaskCell + Send> Remote<T> {
self.core.push(0, t);
}

/// Gets the task queue statistics of the thread pool.
pub fn queue_statistics(&self) -> QueueStatistics {
self.core.queue_statistics()
}

pub(crate) fn stop(&self) {
self.core.mark_shutdown(0);
}
Expand Down
17 changes: 0 additions & 17 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mod single_level;

pub use self::extras::Extras;

use self::multilevel::MultilevelStatistics;
use std::time::Instant;

/// A cell containing a task and needed extra information.
Expand Down Expand Up @@ -60,13 +59,6 @@ impl<T: TaskCell + Send> TaskInjector<T> {
InjectorInner::Multilevel(_) => Extras::multilevel_default(),
}
}

pub(super) fn statistics(&self) -> QueueStatistics {
match &self.0 {
InjectorInner::SingleLevel(_) => QueueStatistics::SingleLevel,
InjectorInner::Multilevel(q) => QueueStatistics::Multilevel(q.statistics()),
}
}
}

/// Popped task cell from a task queue.
Expand Down Expand Up @@ -116,15 +108,6 @@ impl<T: TaskCell + Send> LocalQueue<T> {
}
}

/// Statistics of the task queue.
pub enum QueueStatistics {
// TODO: add statistics for single level queue
/// Statistics of a single-level queue.
SingleLevel,
/// Statistics of a multilevel queue.
Multilevel(MultilevelStatistics),
}

/// Supported available queues.
pub enum QueueType {
/// A single level work stealing queue.
Expand Down
Loading

0 comments on commit 074f36e

Please sign in to comment.