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

write batch with capacity #1846

Merged
merged 4 commits into from May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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.

26 changes: 26 additions & 0 deletions benches/writebatch/bench_writebatch.rs
Expand Up @@ -91,3 +91,29 @@ fn bench_writebatch_512(b: &mut Bencher) {
fn bench_writebatch_1024(b: &mut Bencher) {
bench_writebatch_impl(b, 1024);
}

fn fill_writebatch(wb: &WriteBatch, target_size: usize) {
let (k, v) = (b"this is the key", b"this is the value");
loop {
wb.put(k, v).unwrap();
if wb.data_size() >= target_size {
break;
}
}
}

#[bench]
fn bench_writebatch_without_capacity(b: &mut Bencher) {
b.iter(|| {
let wb = WriteBatch::new();
fill_writebatch(&wb, 4096);
});
}

#[bench]
fn bench_writebatch_with_capacity(b: &mut Bencher) {
b.iter(|| {
let wb = WriteBatch::with_capacity(4096);
fill_writebatch(&wb, 4096);
});
}
3 changes: 2 additions & 1 deletion src/raftstore/store/peer.rs
Expand Up @@ -55,6 +55,7 @@ use super::metrics::*;
use super::local_metrics::{RaftReadyMetrics, RaftMessageMetrics, RaftProposeMetrics, RaftMetrics};

const TRANSFER_LEADER_ALLOW_LOG_LAG: u64 = 10;
const DEFAULT_APPEND_WB_SIZE: usize = 4 * 1024;

struct ReadIndexRequest {
uuid: Uuid,
Expand Down Expand Up @@ -146,7 +147,7 @@ pub struct ReadyContext<'a, T: 'a> {
impl<'a, T> ReadyContext<'a, T> {
pub fn new(metrics: &'a mut RaftMetrics, t: &'a T, cap: usize) -> ReadyContext<'a, T> {
ReadyContext {
wb: WriteBatch::new(),
wb: WriteBatch::with_capacity(DEFAULT_APPEND_WB_SIZE),
metrics: metrics,
trans: t,
ready_res: Vec::with_capacity(cap),
Expand Down
5 changes: 3 additions & 2 deletions src/raftstore/store/worker/apply.rs
Expand Up @@ -41,6 +41,7 @@ use raftstore::store::peer::{parse_data_at, check_epoch, Peer};
use raftstore::store::metrics::*;

const WRITE_BATCH_MAX_KEYS: usize = 128;
const DEFAULT_APPLY_WB_SIZE: usize = 4 * 1024;

pub struct PendingCmd {
pub uuid: Uuid,
Expand Down Expand Up @@ -148,7 +149,7 @@ impl<'a> ApplyContext<'a> {
fn new(host: &CoprocessorHost) -> ApplyContext {
ApplyContext {
host: host,
wb: Some(WriteBatch::new()),
wb: Some(WriteBatch::with_capacity(DEFAULT_APPLY_WB_SIZE)),
cbs: vec![],
wb_last_bytes: 0,
wb_last_keys: 0,
Expand Down Expand Up @@ -376,7 +377,7 @@ impl ApplyDelegate {
for (cb, resp) in apply_ctx.cbs.drain(..) {
cb(resp);
}
apply_ctx.wb = Some(WriteBatch::new());
apply_ctx.wb = Some(WriteBatch::with_capacity(DEFAULT_APPLY_WB_SIZE));
apply_ctx.mark_last_bytes_and_keys();
}

Expand Down