Skip to content

Commit

Permalink
add recycle log configuration (#297)
Browse files Browse the repository at this point in the history
* add recycle log configuration

Signed-off-by: siddontang <siddontang@gmail.com>
  • Loading branch information
siddontang committed Jun 14, 2019
1 parent 9940d00 commit b3410db
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exclude = [
".travis.yml",
"deploy.sh",
"tests/**/*",
"benches/**/*",
]

[features]
Expand Down
82 changes: 82 additions & 0 deletions benches/cases/bench_wal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

use super::rocksdb::{ColumnFamilyOptions, DBOptions, WriteOptions, DB};
use super::tempdir::TempDir;

use super::test::Bencher;

fn run_bench_wal(b: &mut Bencher, name: &str, mut opts: DBOptions, wopts: WriteOptions) {
let path = TempDir::new(name).expect("");
let path_str = path.path().to_str().unwrap();
opts.create_if_missing(true);
opts.set_max_background_jobs(6);
opts.set_max_subcompactions(2);

let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.set_write_buffer_size(16 * 1024);
cf_opts.set_max_write_buffer_number(10);

let db = DB::open_cf(opts, path_str, vec![("default", cf_opts)]).unwrap();

let value = vec![1; 1024];

let mut i = 0;
b.iter(|| {
let key = format!("key_{}", i);
db.put_opt(key.as_bytes(), &value, &wopts).unwrap();
i += 1;
});

drop(db);
}

fn run_bench_wal_recycle_log(b: &mut Bencher, name: &str, recycled: bool) {
let mut opts = DBOptions::new();
if recycled {
opts.set_recycle_log_file_num(10);
}

let mut wopts = WriteOptions::new();
wopts.set_sync(true);

run_bench_wal(b, name, opts, wopts);
}

#[bench]
fn bench_wal_with_recycle_log(b: &mut Bencher) {
run_bench_wal_recycle_log(b, "_rust_rocksdb_wal_with_recycle_log", true);
}

#[bench]
fn bench_wal_without_recycle_log(b: &mut Bencher) {
run_bench_wal_recycle_log(b, "_rust_rocksdb_wal_without_recycle_log", false);
}

#[bench]
fn bench_wal_no_sync(b: &mut Bencher) {
let opts = DBOptions::new();
let mut wopts = WriteOptions::new();
wopts.set_sync(false);

run_bench_wal(b, "_rust_rocksdb_wal_no_sync", opts, wopts);
}

#[bench]
fn bench_wal_disalbe_wal(b: &mut Bencher) {
let opts = DBOptions::new();
let mut wopts = WriteOptions::new();
wopts.disable_wal(true);

run_bench_wal(b, "_rust_rocksdb_wal_disable_wal", opts, wopts);
}
9 changes: 9 additions & 0 deletions benches/cases/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extern crate test;

extern crate byteorder;
extern crate crc;
extern crate rand;
extern crate rocksdb;
extern crate tempdir;

mod bench_wal;
17 changes: 17 additions & 0 deletions benches/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(test)]
extern crate test;

mod cases;
1 change: 1 addition & 0 deletions librocksdb_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ extern "C" {
pub fn crocksdb_options_set_log_file_time_to_roll(options: *mut Options, bytes: size_t);
pub fn crocksdb_options_set_info_log_level(options: *mut Options, level: DBInfoLogLevel);
pub fn crocksdb_options_set_keep_log_file_num(options: *mut Options, num: size_t);
pub fn crocksdb_options_set_recycle_log_file_num(options: *mut Options, num: size_t);
pub fn crocksdb_options_set_max_manifest_file_size(options: *mut Options, bytes: u64);
pub fn crocksdb_options_set_hash_skip_list_rep(
options: *mut Options,
Expand Down
6 changes: 6 additions & 0 deletions src/rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,12 @@ impl DBOptions {
}
}

pub fn set_recycle_log_file_num(&mut self, num: u64) {
unsafe {
crocksdb_ffi::crocksdb_options_set_recycle_log_file_num(self.inner, num as size_t);
}
}

pub fn set_compaction_readahead_size(&mut self, size: u64) {
unsafe {
crocksdb_ffi::crocksdb_options_set_compaction_readahead_size(
Expand Down
1 change: 1 addition & 0 deletions tests/cases/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn test_log_file_opt() {
opts.create_if_missing(true);
opts.set_max_log_file_size(100 * 1024 * 1024);
opts.set_keep_log_file_num(10);
opts.set_recycle_log_file_num(10);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
drop(db);
}
Expand Down

0 comments on commit b3410db

Please sign in to comment.