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

Reset RocksDB statistics periodically #2443

Merged
merged 2 commits into from Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions src/bin/tikv-server.rs
Expand Up @@ -70,7 +70,7 @@ use tikv::server::resolve;
use tikv::raftstore::store::{self, Engines, SnapManager};
use tikv::pd::{PdClient, RpcClient};
use tikv::util::time::Monitor;
use tikv::util::rocksdb::metrics_flusher::{MetricsFlusher, DEFAULT_FLUSER_INTERVAL};
use tikv::util::rocksdb::metrics_flusher::{MetricsFlusher, DEFAULT_FLUSHER_INTERVAL};

const RESERVED_OPEN_FDS: u64 = 1000;

Expand Down Expand Up @@ -232,7 +232,7 @@ fn run_raft_server(pd_client: RpcClient, cfg: &TiKvConfig) {

let mut metrics_flusher = MetricsFlusher::new(
engines.clone(),
Duration::from_millis(DEFAULT_FLUSER_INTERVAL),
Duration::from_millis(DEFAULT_FLUSHER_INTERVAL),
);

// Start metrics flusher
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Expand Up @@ -89,7 +89,7 @@ macro_rules! build_cf_opt {
($opt:ident) => {{
let mut block_base_opts = BlockBasedOptions::new();
block_base_opts.set_block_size($opt.block_size.0 as usize);
block_base_opts.set_lru_cache($opt.block_cache_size.0 as usize);
block_base_opts.set_lru_cache($opt.block_cache_size.0 as usize, -1, 0, 0.0);
block_base_opts.set_cache_index_and_filter_blocks($opt.cache_index_and_filter_blocks);
block_base_opts.set_pin_l0_filter_and_index_blocks_in_cache(
$opt.pin_l0_filter_and_index_blocks);
Expand Down
12 changes: 10 additions & 2 deletions src/util/rocksdb/metrics_flusher.rs
Expand Up @@ -17,9 +17,10 @@ use util::rocksdb::engine_metrics::*;
use std::thread::{Builder, JoinHandle};
use std::io;
use std::sync::mpsc::{self, Sender};
use std::time::Duration;
use std::time::{Duration, Instant};

pub const DEFAULT_FLUSER_INTERVAL: u64 = 10000;
pub const DEFAULT_FLUSHER_INTERVAL: u64 = 10000;
pub const DEFAULT_FLUSHER_RESET_INTERVAL: u64 = 300000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 300s too long?


pub struct MetricsFlusher {
engines: Engines,
Expand Down Expand Up @@ -47,9 +48,16 @@ impl MetricsFlusher {
let h = Builder::new()
.name(thd_name!("rocksb-metrics-flusher"))
.spawn(move || {
let mut last_reset = Instant::now();
let reset_interval = Duration::from_millis(DEFAULT_FLUSHER_RESET_INTERVAL);
while let Err(mpsc::RecvTimeoutError::Timeout) = rx.recv_timeout(interval) {
flush_metrics(&db, "kv");
flush_metrics(&raft_db, "raft");
if last_reset.elapsed() >= reset_interval {
db.reset_statistics();
raft_db.reset_statistics();
last_reset = Instant::now();
}
}
})?;

Expand Down