Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
286bd66b
Commit
286bd66b
authored
Dec 15, 2014
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more configuration capabilities
parent
acba1781
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
31 deletions
+90
-31
README.md
README.md
+35
-0
ffi.rs
src/ffi.rs
+44
-10
lib.rs
src/lib.rs
+1
-0
main.rs
src/main.rs
+10
-21
rocksdb.rs
src/rocksdb.rs
+0
-0
No files found.
README.md
View file @
286bd66b
...
...
@@ -67,6 +67,41 @@ fn main() {
}
```
###### Apply Some Tunings
Please read
[
the official tuning guide
](
https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide
)
, and most importantly, measure performance under realistic workloads with realistic hardware.
```
rust
use
rocksdb
::{
RocksDBOptions
,
RocksDB
,
new_bloom_filter
};
use
rocksdb
::
RocksDBCompactionStyle
::
RocksDBUniversalCompaction
;
fn
tuned_for_somebody_elses_disk
()
->
RocksDB
{
let
path
=
"_rust_rocksdb_optimizetest"
;
let
opts
=
RocksDBOptions
::
new
();
opts
.create_if_missing
(
true
);
opts
.set_block_size
(
524288
);
opts
.set_max_open_files
(
10000
);
opts
.set_use_fsync
(
false
);
opts
.set_bytes_per_sync
(
8388608
);
opts
.set_disable_data_sync
(
false
);
opts
.set_block_cache_size_mb
(
1024
);
opts
.set_table_cache_num_shard_bits
(
6
);
opts
.set_max_write_buffer_number
(
32
);
opts
.set_write_buffer_size
(
536870912
);
opts
.set_target_file_size_base
(
1073741824
);
opts
.set_min_write_buffer_number_to_merge
(
4
);
opts
.set_level_zero_stop_writes_trigger
(
2000
);
opts
.set_level_zero_slowdown_writes_trigger
(
0
);
opts
.set_compaction_style
(
RocksDBUniversalCompaction
);
opts
.set_max_background_compactions
(
4
);
opts
.set_max_background_flushes
(
4
);
opts
.set_filter_deletes
(
false
);
opts
.set_disable_auto_compactions
(
true
);
let
filter
=
new_bloom_filter
(
10
);
opts
.set_filter
(
filter
);
RocksDB
::
open
(
opts
,
path
)
.unwrap
()
}
```
### status
-
[
x
]
basic open/put/get/delete/close
...
...
src/ffi.rs
View file @
286bd66b
...
...
@@ -10,12 +10,20 @@ pub struct RocksDBWriteOptions(pub *const c_void);
#[repr(C)]
pub
struct
RocksDBReadOptions
(
pub
*
const
c_void
);
#[repr(C)]
pub
struct
RocksDBCompactionFilter
(
pub
*
const
c_void
);
#[repr(C)]
pub
struct
RocksDBMergeOperator
(
pub
*
const
c_void
);
#[repr(C)]
pub
struct
RocksDBBlockBasedTableOptions
(
pub
*
const
c_void
);
#[repr(C)]
pub
struct
RocksDBCache
(
pub
*
const
c_void
);
#[repr(C)]
pub
struct
RocksDBFilterPolicy
(
pub
*
const
c_void
);
pub
fn
new_bloom_filter
(
bits
:
c_int
)
->
RocksDBFilterPolicy
{
unsafe
{
rocksdb_filterpolicy_create_bloom
(
bits
)
}
}
#[repr(C)]
pub
enum
RocksDBCompressionType
{
RocksDBNoCompression
=
0
,
...
...
@@ -42,12 +50,41 @@ pub enum RocksDBUniversalCompactionStyle {
#[link(name
=
"rocksdb"
)]
extern
{
pub
fn
rocksdb_options_create
()
->
RocksDBOptions
;
pub
fn
rocksdb_cache_create_lru
(
capacity
:
size_t
)
->
RocksDBCache
;
pub
fn
rocksdb_cache_destroy
(
cache
:
RocksDBCache
);
pub
fn
rocksdb_block_based_options_create
()
->
RocksDBBlockBasedTableOptions
;
pub
fn
rocksdb_block_based_options_destroy
(
block_options
:
RocksDBBlockBasedTableOptions
);
pub
fn
rocksdb_block_based_options_set_block_size
(
block_options
:
RocksDBBlockBasedTableOptions
,
block_size
:
size_t
);
pub
fn
rocksdb_block_based_options_set_block_size_deviation
(
block_options
:
RocksDBBlockBasedTableOptions
,
block_size_deviation
:
c_int
);
pub
fn
rocksdb_block_based_options_set_block_restart_interval
(
block_options
:
RocksDBBlockBasedTableOptions
,
block_restart_interval
:
c_int
);
pub
fn
rocksdb_block_based_options_set_filter_policy
(
block_options
:
RocksDBBlockBasedTableOptions
,
filter_policy
:
RocksDBFilterPolicy
);
pub
fn
rocksdb_block_based_options_set_no_block_cache
(
block_options
:
RocksDBBlockBasedTableOptions
,
no_block_cache
:
bool
);
pub
fn
rocksdb_block_based_options_set_block_cache
(
block_options
:
RocksDBBlockBasedTableOptions
,
block_cache
:
RocksDBCache
);
pub
fn
rocksdb_block_based_options_set_block_cache_compressed
(
block_options
:
RocksDBBlockBasedTableOptions
,
block_cache_compressed
:
RocksDBCache
);
pub
fn
rocksdb_block_based_options_set_whole_key_filtering
(
ck_options
:
RocksDBBlockBasedTableOptions
,
doit
:
bool
);
pub
fn
rocksdb_options_set_block_based_table_factory
(
options
:
RocksDBOptions
,
block_options
:
RocksDBBlockBasedTableOptions
);
pub
fn
rocksdb_options_increase_parallelism
(
options
:
RocksDBOptions
,
threads
:
c_int
);
pub
fn
rocksdb_options_optimize_level_style_compaction
(
options
:
RocksDBOptions
,
memtable_memory_budget
:
c_int
);
pub
fn
rocksdb_options_set_create_if_missing
(
options
:
RocksDBOptions
,
v
:
c_int
);
options
:
RocksDBOptions
,
v
:
bool
);
pub
fn
rocksdb_options_set_max_open_files
(
options
:
RocksDBOptions
,
files
:
c_int
);
pub
fn
rocksdb_options_set_use_fsync
(
...
...
@@ -59,11 +96,9 @@ extern {
pub
fn
rocksdb_options_optimize_for_point_lookup
(
options
:
RocksDBOptions
,
block_cache_size_mb
:
u64
);
pub
fn
rocksdb_options_set_table_cache_numshardbits
(
options
:
RocksDBOptions
,
bits
:
u64
);
options
:
RocksDBOptions
,
bits
:
c_int
);
pub
fn
rocksdb_options_set_max_write_buffer_number
(
options
:
RocksDBOptions
,
bufno
:
c_int
);
pub
fn
rocksdb_options_set_max_write_buffer_number_to_merge
(
options
:
RocksDBOptions
,
bufno
:
c_int
);
pub
fn
rocksdb_options_set_min_write_buffer_number_to_merge
(
options
:
RocksDBOptions
,
bufno
:
c_int
);
pub
fn
rocksdb_options_set_level0_file_num_compaction_trigger
(
...
...
@@ -93,10 +128,9 @@ extern {
pub
fn
rocksdb_options_set_max_background_flushes
(
options
:
RocksDBOptions
,
max_bg_flushes
:
c_int
);
pub
fn
rocksdb_options_set_filter_deletes
(
options
:
RocksDBOptions
,
v
:
u8
);
options
:
RocksDBOptions
,
v
:
bool
);
pub
fn
rocksdb_options_set_disable_auto_compactions
(
options
:
RocksDBOptions
,
v
:
u8
);
//pub fn rocksdb_compactionfilter_create() -> RocksDBCompactionFilter;
options
:
RocksDBOptions
,
v
:
c_int
);
pub
fn
rocksdb_filterpolicy_create_bloom
(
bits_per_key
:
c_int
)
->
RocksDBFilterPolicy
;
pub
fn
rocksdb_open
(
options
:
RocksDBOptions
,
...
...
@@ -156,7 +190,7 @@ fn internal() {
rocksdb_options_increase_parallelism
(
opts
,
0
);
rocksdb_options_optimize_level_style_compaction
(
opts
,
0
);
rocksdb_options_set_create_if_missing
(
opts
,
1
);
rocksdb_options_set_create_if_missing
(
opts
,
true
);
let
rustpath
=
"_rust_rocksdb_internaltest"
;
let
cpath
=
rustpath
.to_c_str
();
...
...
src/lib.rs
View file @
286bd66b
...
...
@@ -4,6 +4,7 @@
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
::{
new_bloom_filter
,
RocksDBUniversalCompactionStyle
,
RocksDBCompactionStyle
,
RocksDBCompressionType
,
...
...
src/main.rs
View file @
286bd66b
extern
crate
rocksdb
;
extern
crate
test
;
use
rocksdb
::{
RocksDBOptions
,
RocksDB
,
MergeOperands
};
use
rocksdb
::{
RocksDBOptions
,
RocksDB
,
MergeOperands
,
new_bloom_filter
};
use
rocksdb
::
RocksDBCompactionStyle
::
RocksDBUniversalCompaction
;
use
test
::
Bencher
;
...
...
@@ -24,7 +24,6 @@ fn main() {
db
.close
();
custom_merge
();
optimized
();
}
#[allow(dead_code)]
...
...
@@ -61,7 +60,7 @@ fn custom_merge() {
}
#[allow(dead_code)]
fn
optimized
()
{
fn
tuned_for_somebody_elses_disk
()
->
RocksDB
{
let
path
=
"_rust_rocksdb_optimizetest"
;
let
opts
=
RocksDBOptions
::
new
();
opts
.create_if_missing
(
true
);
...
...
@@ -70,7 +69,7 @@ fn optimized() {
opts
.set_use_fsync
(
false
);
opts
.set_bytes_per_sync
(
8388608
);
opts
.set_disable_data_sync
(
false
);
opts
.set_
cache_size
(
8589934592
);
opts
.set_
block_cache_size_mb
(
1024
);
opts
.set_table_cache_num_shard_bits
(
6
);
opts
.set_max_write_buffer_number
(
32
);
opts
.set_write_buffer_size
(
536870912
);
...
...
@@ -78,32 +77,22 @@ fn optimized() {
opts
.set_min_write_buffer_number_to_merge
(
4
);
opts
.set_level_zero_stop_writes_trigger
(
2000
);
opts
.set_level_zero_slowdown_writes_trigger
(
0
);
//opts.set_memtable_config(newSkipListMemTableConfig());
opts
.set_compaction_style
(
RocksDBUniversalCompaction
);
opts
.set_max_background_compactions
(
4
);
opts
.set_max_background_flushes
(
4
);
opts
.set_filter_deletes
(
false
);
opts
.set_disable_auto_compaction
(
true
);
//opts.set_filter(filter);
opts
.set_disable_auto_compactions
(
true
);
opts
.add_merge_operator
(
"test operator"
,
concat_merge
);
let
db
=
RocksDB
::
open
(
opts
,
path
)
.unwrap
();
let
p
=
db
.put
(
b
"k1"
,
b
"a"
);
db
.merge
(
b
"k1"
,
b
"b"
);
db
.merge
(
b
"k1"
,
b
"c"
);
db
.merge
(
b
"k1"
,
b
"d"
);
db
.merge
(
b
"k1"
,
b
"efg"
);
let
m
=
db
.merge
(
b
"k1"
,
b
"h"
);
let
r
=
db
.get
(
b
"k1"
);
assert
!
(
r
.unwrap
()
.to_utf8
()
.unwrap
()
==
"abcdefgh"
);
db
.close
();
RocksDB
::
destroy
(
opts
,
path
)
.is_ok
();
let
filter
=
new_bloom_filter
(
10
);
opts
.set_filter
(
filter
);
RocksDB
::
open
(
opts
,
path
)
.unwrap
()
}
#[allow(dead_code)]
#[bench]
fn
writes
(
b
:
&
mut
Bencher
)
{
let
db
=
RocksDB
::
open_default
(
"testdb"
)
.unwrap
();
let
db
=
tuned_for_somebody_elses_disk
();
let
mut
i
=
0
as
u64
;
b
.iter
(||
{
db
.put
(
i
.to_string
()
.as_bytes
(),
b
"v1111"
);
...
...
@@ -115,7 +104,7 @@ fn writes(b: &mut Bencher) {
#[allow(dead_code)]
#[bench]
fn
reads
(
b
:
&
mut
Bencher
)
{
let
db
=
RocksDB
::
open_default
(
"testdb"
)
.unwrap
();
let
db
=
tuned_for_somebody_elses_disk
();
let
mut
i
=
0
as
u64
;
b
.iter
(||
{
db
.get
(
i
.to_string
()
.as_bytes
())
.on_error
(
|
e
|
{
...
...
src/rocksdb.rs
View file @
286bd66b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment