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

Add random get mode in bobp #225

Merged
merged 10 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bob versions changelog
- Use default config in dockerfiles ([#290](https://github.com/qoollo/bob/pull/309))
- Add log file rotation to logger.yaml in examples ([#297](https://github.com/qoollo/bob/pull/297))
- Build docker images with build workflow ([#308](https://github.com/qoollo/bob/pull/308))
- Add random mode in get in bobp ([#215](https://github.com/qoollo/bob/pull/225))

#### Changed

Expand Down
1 change: 1 addition & 0 deletions bob-apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tower-load = "0.3.0"
tower-make = "0.3.0"
tower-service = "0.3.0"
#metrics = "0.12.1"
rand = "0.8"
bincode = "1.3"
crc = "1.8"

Expand Down
38 changes: 36 additions & 2 deletions bob-apps/bin/bobp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use rand::prelude::*;

use bob::{
Blob, BlobKey, BlobMeta, BobApiClient, ExistRequest, GetOptions, GetRequest, GetSource,
PutOptions, PutRequest,
Expand Down Expand Up @@ -69,18 +71,30 @@ impl Debug for NetConfig {
}
}

#[derive(Clone, PartialEq)]
enum Mode {
Normal,
Random,
}

#[derive(Clone)]
struct TaskConfig {
low_idx: u64,
count: u64,
payload_size: u64,
direct: bool,
mode: Mode,
measure_time: bool,
key_size: usize,
}

impl TaskConfig {
fn from_matches(matches: &ArgMatches) -> Self {
let mode = if matches.is_present("random") {
Mode::Random
} else {
Mode::Normal
};
let key_size = matches.value_or_default("keysize");
let low_idx = matches.value_or_default("first");
let count = matches.value_or_default("count");
Expand All @@ -100,6 +114,7 @@ impl TaskConfig {
count,
payload_size: matches.value_or_default("payload"),
direct: matches.is_present("direct"),
mode,
measure_time: false,
key_size,
}
Expand Down Expand Up @@ -132,6 +147,10 @@ impl TaskConfig {
self.measure_time
}

fn is_random(&self) -> bool {
self.mode == Mode::Random
}

fn get_proper_key(&self, key: u64) -> Vec<u8> {
let mut data = key.to_le_bytes().to_vec();
data.resize(self.key_size, 0);
Expand Down Expand Up @@ -471,10 +490,17 @@ async fn get_worker(net_conf: NetConfig, task_conf: TaskConfig, stat: Arc<Statis
let options = task_conf.find_get_options();
let upper_idx = task_conf.low_idx + task_conf.count;
let measure_time = task_conf.is_time_measurement_thread();
for i in task_conf.low_idx..upper_idx {
let iterator: Box<dyn Send + Iterator<Item = u64>> = if task_conf.is_random() {
Box::new(task_conf.low_idx..upper_idx)
} else {
let mut keys: Vec<_> = (task_conf.low_idx..upper_idx).collect();
keys.shuffle(&mut thread_rng());
Box::new(keys.into_iter())
};
for key in iterator {
let request = Request::new(GetRequest {
key: Some(BlobKey {
key: task_conf.get_proper_key(i),
key: task_conf.get_proper_key(key),
}),
options: options.clone(),
});
Expand Down Expand Up @@ -619,6 +645,7 @@ fn spawn_workers(
count,
payload_size: task_conf.payload_size,
direct: task_conf.direct,
mode: task_conf.mode.clone(),
measure_time: i == 0,
key_size: task_conf.key_size,
};
Expand Down Expand Up @@ -737,6 +764,13 @@ fn get_matches() -> ArgMatches<'static> {
.takes_value(false)
.long("verify"),
)
.arg(
Arg::with_name("random")
Justarone marked this conversation as resolved.
Show resolved Hide resolved
.help("keys in get operation are shuffled")
.takes_value(false)
Justarone marked this conversation as resolved.
Show resolved Hide resolved
.short("r")
.long("random"),
)
.arg(
Arg::with_name("keysize")
.help("size of the binary key")
Expand Down