Skip to content

Commit

Permalink
DOSE-21 hit-rate-per-size reporting (openzfs#9)
Browse files Browse the repository at this point in the history
Add a new hit-by-size histogram to zettacache that is updated whenever
there is a successful lookup (for read). This captures the minimum cache
size that would contain this block.

Add a new command (zcache) that has subcommands to display
and clear the new histogram.
  • Loading branch information
mmaybee authored Nov 23, 2021
1 parent 288fabe commit 5929d24
Show file tree
Hide file tree
Showing 31 changed files with 876 additions and 215 deletions.
2 changes: 1 addition & 1 deletion cmd/zdb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ zdb_LDADD = \

if BUILD_RUST
zdb_LDADD += -lzoa
zdb_LDFLAGS = -L$(abs_top_builddir)/cmd/zfs_object_agent
zdb_LDFLAGS = -L$(abs_top_builddir)/cmd/zfs_object_agent/$(RUSTDIR)
zdb_CFLAGS = -DHAVE_LIBZOA
endif

Expand Down
35 changes: 31 additions & 4 deletions cmd/zfs_object_agent/Cargo.lock

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

1 change: 1 addition & 0 deletions cmd/zfs_object_agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"object_perf",
"server",
"util",
"zcache",
"zcdb",
"zettacache",
"zettaobject",
Expand Down
38 changes: 20 additions & 18 deletions cmd/zfs_object_agent/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
lib_LTLIBRARIES = libzoa.la
lib_LTLIBRARIES = $(RUSTDIR)/libzoa.la

sbin_PROGRAMS = zcachedb zfs_object_agent zfs_object_perf zoa_test
sbin_PROGRAMS = $(RUSTDIR)/zcache $(RUSTDIR)/zcachedb $(RUSTDIR)/zfs_object_agent $(RUSTDIR)/zfs_object_perf $(RUSTDIR)/zoa_test

common_sources = $(wildcard util/src/*.rs util/Cargo.toml zettacache/src/*.rs zettacache/Cargo.toml zettaobject/src/*.rs zettaobject/Cargo.toml Cargo.lock Cargo.toml)

zcachedb_SOURCES = $(wildcard zcdb/src/*.rs zcdb/Cargo.toml) $(common_sources)
__RUSTDIR__zcache_SOURCES = $(wildcard zcache/src/*.rs zcache/Cargo.toml) $(common_sources)

zfs_object_agent_SOURCES = $(wildcard server/src/*.rs server/Cargo.toml) $(common_sources)
__RUSTDIR__zcachedb_SOURCES = $(wildcard zcdb/src/*.rs zcdb/Cargo.toml) $(common_sources)

zfs_object_perf_SOURCES = $(wildcard object_perf/src/*.rs object_perf/Cargo.toml) $(common_sources)
__RUSTDIR__zfs_object_agent_SOURCES = $(wildcard server/src/*.rs server/Cargo.toml) $(common_sources)

zoa_test_SOURCES = $(wildcard client/src/*.rs client/Cargo.toml) $(common_sources)
__RUSTDIR__zfs_object_perf_SOURCES = $(wildcard object_perf/src/*.rs object_perf/Cargo.toml) $(common_sources)

libzoa_la_SOURCES = $(wildcard zoa/src/*.rs zoa/Cargo.toml) $(common_sources)
__RUSTDIR__zoa_test_SOURCES = $(wildcard client/src/*.rs client/Cargo.toml) $(common_sources)

__RUSTDIR__libzoa_la_SOURCES = $(wildcard zoa/src/*.rs zoa/Cargo.toml) $(common_sources)

RUSTFLAGS = \
-L $(abs_top_builddir)/lib/libzfs/.libs \
Expand All @@ -21,40 +23,40 @@ RUSTFLAGS = \
GITREV = $(shell cat $(abs_top_builddir)/include/zfs_gitrev.h | awk '{print $$3}')

.PHONY: \
zcache$(EXEEXT) \
zcachedb$(EXEEXT) \
zfs_object_agent$(EXEEXT) \
zfs_object_perf$(EXEEXT) \
zoa_test$(EXEEXT) \
libzoa.la

libzoa.la :
$(RUSTDIR)/libzoa.la :
CARGO_ZOA_GITREV="$(GITREV)" RUSTFLAGS="$(RUSTFLAGS)" cargo build --package zoa $(RUSTTARGET)
cp target/@RUSTDIR@/libzoa.so .

zfs_object_agent$(EXEEXT) :
$(RUSTDIR)/zfs_object_agent$(EXEEXT) :
CARGO_ZOA_GITREV="$(GITREV)" RUSTFLAGS="$(RUSTFLAGS)" cargo build --package zfs_object_agent $(RUSTTARGET)
cp target/@RUSTDIR@/zfs_object_agent .

zfs_object_perf$(EXEEXT) :
$(RUSTDIR)/zfs_object_perf$(EXEEXT) :
CARGO_ZOA_GITREV="$(GITREV)" RUSTFLAGS="$(RUSTFLAGS)" cargo build --package zfs_object_perf $(RUSTTARGET)
cp target/@RUSTDIR@/zfs_object_perf .

zoa_test$(EXEEXT) :
$(RUSTDIR)/zoa_test$(EXEEXT) :
CARGO_ZOA_GITREV="$(GITREV)" RUSTFLAGS="$(RUSTFLAGS)" cargo build --package zoa_test $(RUSTTARGET)
cp target/@RUSTDIR@/zoa_test .

zcachedb$(EXEEXT) :
$(RUSTDIR)/zcachedb$(EXEEXT) :
CARGO_ZOA_GITREV="$(GITREV)" RUSTFLAGS="$(RUSTFLAGS)" cargo build --package zcachedb $(RUSTTARGET)
cp target/@RUSTDIR@/zcachedb .

$(RUSTDIR)/zcache$(EXEEXT) :
CARGO_ZOA_GITREV="$(GITREV)" RUSTFLAGS="$(RUSTFLAGS)" cargo build --package zcache $(RUSTTARGET)

all: build

build: \
libzoa.la \
zcache$(EXEEXT) \
zcachedb$(EXEEXT) \
zfs_object_agent$(EXEEXT) \
zfs_object_perf$(EXEEXT) \
zoa_test$(EXEEXT)

install-exec-hook :
cp target/@RUSTDIR@/libzoa.so $(DESTDIR)$(libdir)/libzoa.so
cp $(RUSTDIR)/libzoa.so $(DESTDIR)$(libdir)/libzoa.so
1 change: 1 addition & 0 deletions cmd/zfs_object_agent/object_perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ futures = "0.3.16"
serde = { version = "1.0.125", features = ["derive"] }
uuid = {version = "0.8"}
tokio = { version = "1.4", features = ["full"] }
util = { path = "../util" }
zettaobject = { path = "../zettaobject" }
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/object_perf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async fn main() {
.subcommand(SubCommand::with_name("read").about("read test"))
.get_matches();

zettaobject::init::setup_logging(
util::setup_logging(
matches.occurrences_of("verbosity"),
matches.value_of("output-file"),
matches.value_of("log-config"),
Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn main() {
let socket_dir = matches.value_of("socket-dir").unwrap();
let cache_path = matches.value_of("cache-file");

zettaobject::init::setup_logging(
util::setup_logging(
matches.occurrences_of("verbosity"),
matches.value_of("output-file"),
matches.value_of("log-config"),
Expand Down
1 change: 1 addition & 0 deletions cmd/zfs_object_agent/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bytes = "1.0"
config = "0.11"
lazy_static = "1.4.0"
log = "0.4"
log4rs = "1.0.0"
more-asserts = "0.2.1"
rand = "0.8.3"
roaring = "0.7.0"
Expand Down
2 changes: 2 additions & 0 deletions cmd/zfs_object_agent/util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod bitmap_range_iterator;
mod die;
mod from64;
mod lock_set;
mod logging;
mod mutex_ext;
mod nicenum;
mod range_tree;
Expand All @@ -18,6 +19,7 @@ pub use die::maybe_die_with;
pub use from64::From64;
pub use lock_set::LockSet;
pub use lock_set::LockedItem;
pub use logging::setup_logging;
pub use mutex_ext::MutexExt;
pub use nicenum::nice_p2size;
pub use range_tree::RangeTree;
Expand Down
91 changes: 91 additions & 0 deletions cmd/zfs_object_agent/util/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use lazy_static::lazy_static;
use log::*;
use log4rs::append::console::ConsoleAppender;
use log4rs::append::file::FileAppender;
use log4rs::config::Logger;
use log4rs::config::{Appender, Config, Root};
use log4rs::encode::pattern::PatternEncoder;

lazy_static! {
static ref LOG_PATTERN: String = "[{d(%Y-%m-%d %H:%M:%S%.3f)}][{t}][{l}] {m}{n}".to_string();
}

pub fn get_logging_level(verbosity: u64) -> LevelFilter {
match verbosity {
0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Trace,
}
}

fn setup_console_logging(verbosity: u64) {
let config = Config::builder()
.appender(
Appender::builder().build(
"stdout",
Box::new(
ConsoleAppender::builder()
.encoder(Box::new(PatternEncoder::new(&*LOG_PATTERN)))
.build(),
),
),
)
// rusoto_core::request is very chatty when set to debug. So, set it to info.
.logger(Logger::builder().build("rusoto_core::request", LevelFilter::Info))
.build(
Root::builder()
.appender("stdout")
.build(get_logging_level(verbosity)),
)
.unwrap();

log4rs::init_config(config).unwrap();
}

fn setup_logfile(verbosity: u64, logfile: &str) {
let config = Config::builder()
.appender(
Appender::builder().build(
"logfile",
Box::new(
FileAppender::builder()
.encoder(Box::new(PatternEncoder::new(&*LOG_PATTERN)))
.build(logfile)
.unwrap(),
),
),
)
// rusoto_core::request is very chatty when set to debug. So, set it to info.
.logger(Logger::builder().build("rusoto_core::request", LevelFilter::Info))
.build(
Root::builder()
.appender("logfile")
.build(get_logging_level(verbosity)),
)
.unwrap();

log4rs::init_config(config).unwrap();
}

pub fn setup_logging(verbosity: u64, file_name: Option<&str>, log_config: Option<&str>) {
match log_config {
Some(config) => {
log4rs::init_file(config, Default::default()).unwrap();
}
None => {
match file_name {
Some(logfile) => {
setup_logfile(verbosity, logfile);
}
None => {
/*
* When neither the log_config nor a log file is specified
* log to console.
*/
setup_console_logging(verbosity);
}
}
}
};
}
12 changes: 8 additions & 4 deletions cmd/zfs_object_agent/util/src/nicenum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Functions which provide "nice" looking output for numbers

// Convert an arbitrary integer into a scaled byte length specification
// With up to 4 significant digits (returned string will be <= 6 characters)
/// Convert an arbitrary integer into a scaled byte length specification
/// with up to 4 significant digits (returned string will be <= 6 characters).
pub fn nice_p2size(number: u64) -> String {
let mut scaled: f64 = number as f64;
for unit in ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] {
Expand All @@ -15,6 +15,10 @@ pub fn nice_p2size(number: u64) -> String {
}
};
return format!("{:.*}{}", places, scaled, unit);
} // it isn't possible to get here. 64 bits can only "count" to exabytes
panic!()
}
// it isn't possible to get here. 64 bits can only "count" to exabytes
panic!(
"Coding error encountered; original number: {}, scaled value: {}",
number, scaled
);
}
21 changes: 21 additions & 0 deletions cmd/zfs_object_agent/zcache/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "zcache"
version = "0.1.0"
authors = ["Delphix"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
chrono = "0.4"
async-trait = "0.1.51"
clap = "2"
exitcode = "1.1.2"
libc = "0.2"
log = "0.4"
more-asserts = "0.2.1"
num-traits = "0.2.14"
nvpair = { git = "https://github.com/ahrens/rust-libzfs", branch = "work"}
tokio = { version = "1.4", features = ["full"] }
util = { path = "../util" }
Loading

0 comments on commit 5929d24

Please sign in to comment.