Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Liu Cong <innerr@gmail.com>
  • Loading branch information
innerr committed Aug 10, 2020
1 parent fa59ee8 commit 704cad7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 67 deletions.
68 changes: 24 additions & 44 deletions src/storage/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,15 @@ make_auto_flush_static_metric! {
"type" => CommandKind,
}

pub struct SchedPreHandle1DurationVec: LocalHistogram {
pub struct SchedAsyncSnapshotDurationVec: LocalHistogram {
"type" => CommandKind,
}

pub struct SchedPreHandle2DurationVec: LocalHistogram {
pub struct SchedWaitForThreadDurationVec: LocalHistogram {
"type" => CommandKind,
}

pub struct SchedPreHandle3DurationVec: LocalHistogram {
"type" => CommandKind,
}

pub struct SchedBeforeWrite1DurationVec: LocalHistogram {
"type" => CommandKind,
}

pub struct SchedBeforeWrite2DurationVec: LocalHistogram {
pub struct SchedProcessBeforeWriteDurationVec: LocalHistogram {
"type" => CommandKind,
}

Expand Down Expand Up @@ -422,51 +414,39 @@ lazy_static! {
exponential_buckets(0.0005, 2.0, 20).unwrap()
)
.unwrap();
pub static ref SCHED_PRE_HANDLE_1_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_pre_handle_1_duration_seconds",
"Bucketed histogram of scheduler pre_handle_1 duration.",
pub static ref SCHED_ASYNC_SNAPSHOT_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_async_snapshot_duration_seconds",
"Bucketed histogram of scheduler before-process duration.",
&["type"],
exponential_buckets(0.0005, 2.0, 20).unwrap()
)
.unwrap();
pub static ref SCHED_PRE_HANDLE_1_DURATIONS_VEC: SchedPreHandle1DurationVec =
auto_flush_from!(SCHED_PRE_HANDLE_1_DURATIONS, SchedPreHandle1DurationVec);
pub static ref SCHED_PRE_HANDLE_2_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_pre_handle_2_duration_seconds",
"Bucketed histogram of scheduler pre_handle_2 duration.",
&["type"],
exponential_buckets(0.0005, 2.0, 20).unwrap()
)
.unwrap();
pub static ref SCHED_PRE_HANDLE_2_DURATIONS_VEC: SchedPreHandle2DurationVec =
auto_flush_from!(SCHED_PRE_HANDLE_2_DURATIONS, SchedPreHandle2DurationVec);
pub static ref SCHED_PRE_HANDLE_3_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_pre_handle_3_duration_seconds",
"Bucketed histogram of scheduler pre_handle_3 duration.",
&["type"],
exponential_buckets(0.0005, 2.0, 20).unwrap()
)
.unwrap();
pub static ref SCHED_PRE_HANDLE_3_DURATIONS_VEC: SchedPreHandle3DurationVec =
auto_flush_from!(SCHED_PRE_HANDLE_3_DURATIONS, SchedPreHandle3DurationVec);
pub static ref SCHED_BEFORE_WRITE_1_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_before_write_1_duration_seconds",
"Bucketed histogram of scheduler before_write_1 duration.",
pub static ref SCHED_ASYNC_SNAPSHOT_DURATIONS_VEC: SchedAsyncSnapshotDurationVec = auto_flush_from!(
SCHED_ASYNC_SNAPSHOT_DURATIONS,
SchedAsyncSnapshotDurationVec
);
pub static ref SCHED_WAIT_FOR_THREAD_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_wait_for_thread_duration_seconds",
"Bucketed histogram of scheduler wait-for-thread duration.",
&["type"],
exponential_buckets(0.0005, 2.0, 20).unwrap()
)
.unwrap();
pub static ref SCHED_BEFORE_WRITE_1_DURATIONS_VEC: SchedBeforeWrite1DurationVec =
auto_flush_from!(SCHED_BEFORE_WRITE_1_DURATIONS, SchedBeforeWrite1DurationVec);
pub static ref SCHED_BEFORE_WRITE_2_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_before_write_2_duration_seconds",
"Bucketed histogram of scheduler before_write_2 duration.",
pub static ref SCHED_WAIT_FOR_THREAD_DURATIONS_VEC: SchedWaitForThreadDurationVec = auto_flush_from!(
SCHED_WAIT_FOR_THREAD_DURATIONS,
SchedWaitForThreadDurationVec
);
pub static ref SCHED_PROCESS_BEFORE_WRITE_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_process_before_write_duration_seconds",
"Bucketed histogram of scheduler process-before-write duration.",
&["type"],
exponential_buckets(0.0005, 2.0, 20).unwrap()
)
.unwrap();
pub static ref SCHED_BEFORE_WRITE_2_DURATIONS_VEC: SchedBeforeWrite2DurationVec =
auto_flush_from!(SCHED_BEFORE_WRITE_2_DURATIONS, SchedBeforeWrite2DurationVec);
pub static ref SCHED_PROCESS_BEFORE_WRITE_DURATIONS_VEC: SchedProcessBeforeWriteDurationVec = auto_flush_from!(
SCHED_PROCESS_BEFORE_WRITE_DURATIONS,
SchedProcessBeforeWriteDurationVec
);
pub static ref SCHED_EXEC_CALLBACK_DURATIONS: HistogramVec = register_histogram_vec!(
"tikv_scheduler_exec_callback_duration_seconds",
"Bucketed histogram of scheduler executing callback.",
Expand Down
35 changes: 12 additions & 23 deletions src/storage/txn/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ use crate::storage::{
use crate::storage::metrics::SCHED_POST_HANDLE_DURATIONS_VEC;
use crate::storage::metrics::SCHED_POST_WRITE_DURATIONS_VEC;

// Scheduler command duration == ASYNC_WRITE_DURATIONS_VEC +
// ASYNC_WRITE_DURATIONS_VEC +
// sum duration of below:
use crate::storage::metrics::SCHED_BEFORE_WRITE_1_DURATIONS_VEC;
use crate::storage::metrics::SCHED_BEFORE_WRITE_2_DURATIONS_VEC;
// Scheduler command duration ==
// ASYNC_WRITE_DURATIONS_VEC + sum(durations-of-all-below)
use crate::storage::metrics::SCHED_ASYNC_SNAPSHOT_DURATIONS_VEC;
use crate::storage::metrics::SCHED_EXEC_CALLBACK_DURATIONS_VEC;
use crate::storage::metrics::SCHED_PRE_HANDLE_1_DURATIONS_VEC;
use crate::storage::metrics::SCHED_PRE_HANDLE_2_DURATIONS_VEC;
use crate::storage::metrics::SCHED_PRE_HANDLE_3_DURATIONS_VEC;
use crate::storage::metrics::SCHED_PROCESS_BEFORE_WRITE_DURATIONS_VEC;
use crate::storage::metrics::SCHED_WAIT_FOR_THREAD_DURATIONS_VEC;
use crate::storage::metrics::SCHED_WAIT_HISTOGRAM_VEC;

const TASKS_SLOTS_NUM: usize = 1 << 12; // 4096 slots.
Expand Down Expand Up @@ -392,7 +389,7 @@ impl<E: Engine, L: LockManager, P: PdClient + 'static> Scheduler<E, L, P> {
"process cmd with snapshot";
"cid" => task.cid, "cb_ctx" => ?cb_ctx
);
SCHED_PRE_HANDLE_1_DURATIONS_VEC
SCHED_ASYNC_SNAPSHOT_DURATIONS_VEC
.get(tag)
.observe(timer.elapsed_secs());
sched.process_by_worker(snapshot, task);
Expand Down Expand Up @@ -556,11 +553,6 @@ impl<E: Engine, L: LockManager, P: PdClient + 'static> Scheduler<E, L, P> {
.clone()
.pool
.spawn(async move {
SCHED_PRE_HANDLE_3_DURATIONS_VEC
.get(tag)
.observe(timer.elapsed_secs());
let mut timer = Instant::now_coarse();

fail_point!("scheduler_async_snapshot_finish");

let read_duration = Instant::now_coarse();
Expand All @@ -569,13 +561,14 @@ impl<E: Engine, L: LockManager, P: PdClient + 'static> Scheduler<E, L, P> {
let ts = task.cmd.ts();
let mut statistics = Statistics::default();

SCHED_WAIT_FOR_THREAD_DURATIONS_VEC
.get(tag)
.observe(timer.elapsed_secs());
let timer = Instant::now_coarse();

if task.cmd.readonly() {
self.process_read(snapshot, task, &mut statistics);
} else {
SCHED_PRE_HANDLE_2_DURATIONS_VEC
.get(tag)
.observe(timer.elapsed_secs());
timer = Instant::now_coarse();
// Safety: `self.sched_pool` ensures a TLS engine exists.
unsafe {
with_tls_engine(|engine| {
Expand Down Expand Up @@ -646,10 +639,6 @@ impl<E: Engine, L: LockManager, P: PdClient + 'static> Scheduler<E, L, P> {
pr,
lock_info,
}) => {
SCHED_BEFORE_WRITE_1_DURATIONS_VEC
.get(tag)
.observe(timer.elapsed_secs());
let timer = Instant::now_coarse();
SCHED_STAGE_COUNTER_VEC.get(tag).write.inc();

if let Some((lock, is_first_lock, wait_timeout)) = lock_info {
Expand Down Expand Up @@ -699,7 +688,7 @@ impl<E: Engine, L: LockManager, P: PdClient + 'static> Scheduler<E, L, P> {
res
});

SCHED_BEFORE_WRITE_2_DURATIONS_VEC
SCHED_PROCESS_BEFORE_WRITE_DURATIONS_VEC
.get(tag)
.observe(timer.elapsed_secs());
let timer = Instant::now_coarse();
Expand Down

0 comments on commit 704cad7

Please sign in to comment.