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
mertrics: report region flow #1517
Changes from 7 commits
5b5792a
af98ebe
00c38d3
292adc6
6da818c
01e3a96
8f337fe
8c94727
bb11eae
54d8f88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ use super::cmd_resp::{bind_uuid, bind_term, bind_error}; | |
use super::transport::Transport; | ||
use super::metrics::*; | ||
use super::local_metrics::RaftMetrics; | ||
use prometheus::local::LocalHistogram; | ||
|
||
type Key = Vec<u8>; | ||
|
||
|
@@ -109,6 +110,9 @@ pub struct Store<T: Transport, C: PdClient + 'static> { | |
|
||
start_time: Timespec, | ||
is_busy: bool, | ||
|
||
region_written_bytes: LocalHistogram, | ||
region_written_keys: LocalHistogram, | ||
} | ||
|
||
pub fn create_event_loop<T, C>(cfg: &Config) -> Result<EventLoop<Store<T, C>>> | ||
|
@@ -178,6 +182,8 @@ impl<T: Transport, C: PdClient> Store<T, C> { | |
tag: tag, | ||
start_time: time::get_time(), | ||
is_busy: false, | ||
region_written_bytes: REGION_WRITTEN_BYTES_HISTOGRAM.local(), | ||
region_written_keys: REGION_WRITTEN_KEYS_HISTOGRAM.local(), | ||
}; | ||
try!(s.init()); | ||
Ok(s) | ||
|
@@ -279,6 +285,7 @@ impl<T: Transport, C: PdClient> Store<T, C> { | |
self.register_snap_mgr_gc_tick(event_loop); | ||
self.register_compact_lock_cf_tick(event_loop); | ||
self.register_consistency_check_tick(event_loop); | ||
self.register_report_region_flow_tick(event_loop); | ||
|
||
let split_check_runner = SplitCheckRunner::new(self.sendch.clone(), | ||
self.cfg.region_max_size, | ||
|
@@ -1144,6 +1151,33 @@ impl<T: Transport, C: PdClient> Store<T, C> { | |
}; | ||
} | ||
|
||
fn register_report_region_flow_tick(&self, event_loop: &mut EventLoop<Self>) { | ||
if let Err(e) = register_timer(event_loop, | ||
Tick::ReportRegionFlow, | ||
self.cfg.report_region_flow_interval) { | ||
error!("{} register raft gc log tick err: {:?}", self.tag, e); | ||
}; | ||
} | ||
|
||
fn on_report_region_flow(&mut self, event_loop: &mut EventLoop<Self>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please cover it in test |
||
for (_, peer) in &mut self.region_peers { | ||
if !peer.is_leader() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If peer steps down, all records will be lost. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ok, we don't need exact result. |
||
peer.written_bytes = 0; | ||
peer.written_keys = 0; | ||
continue; | ||
} | ||
|
||
self.region_written_bytes.observe(peer.written_bytes as f64); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why observe it here rather every time handle ready? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, then we can remove the timer here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.region_written_keys.observe(peer.written_keys as f64); | ||
peer.written_bytes = 0; | ||
peer.written_keys = 0; | ||
} | ||
self.region_written_bytes.flush(); | ||
self.region_written_keys.flush(); | ||
|
||
self.register_report_region_flow_tick(event_loop); | ||
} | ||
|
||
#[allow(if_same_then_else)] | ||
fn on_raft_gc_log_tick(&mut self, event_loop: &mut EventLoop<Self>) { | ||
for (®ion_id, peer) in &mut self.region_peers { | ||
|
@@ -1834,6 +1868,7 @@ impl<T: Transport, C: PdClient> mio::Handler for Store<T, C> { | |
Tick::SnapGc => self.on_snap_mgr_gc(event_loop), | ||
Tick::CompactLockCf => self.on_compact_lock_cf(event_loop), | ||
Tick::ConsistencyCheck => self.on_consistency_check_tick(event_loop), | ||
Tick::ReportRegionFlow => self.on_report_region_flow(event_loop), | ||
} | ||
slow_log!(t, "{} handle timeout {:?}", self.tag, timeout); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just
REGION_WRITTEN_KEY_HISTOGRAM
is enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Em, here we may just want to know the written keys rate, if too high, the store may have a high load, so Counter is ok.