Skip to content

Commit 6897bf0

Browse files
authored
Merge pull request #249 from eval-exec/jemalloc
Use tikv-jemallocator on non msvc platform and set rocksdb options
2 parents 182f1ca + 7cd4b1c commit 6897bf0

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

light-client-bin/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ rocksdb = { package = "ckb-rocksdb", version = "=0.21.1", features = [
3333
env_logger = "0.11"
3434
anyhow = "1.0.56"
3535

36+
[target.'cfg(not(target_env = "msvc"))'.dependencies]
37+
tikv-jemallocator = "0.6"
38+
3639
[dev-dependencies]
3740
rand = "0.8"
3841
serde_json = "1.0"

light-client-bin/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ mod tests;
99
use cli::AppConfig;
1010
use env_logger::{Builder, Env, Target};
1111

12+
#[cfg(not(target_env = "msvc"))]
13+
#[global_allocator]
14+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
15+
1216
fn main() -> anyhow::Result<()> {
1317
let mut builder = Builder::from_env(Env::default());
1418
builder.target(Target::Stdout);

light-client-lib/src/storage/db/native.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use ckb_types::{
2121
use rocksdb::{
2222
ops::{Delete, GetPinned},
2323
prelude::{Get, Iterate, Open, Put, WriteOps},
24-
DBPinnableSlice, Direction, IteratorMode, Snapshot, WriteBatch, DB,
24+
DBPinnableSlice, Direction, IteratorMode, Options, Snapshot, WriteBatch, DB,
2525
};
2626
use std::{
2727
collections::{HashMap, HashSet},
@@ -52,7 +52,12 @@ pub struct Storage {
5252

5353
impl Storage {
5454
pub fn new<P: AsRef<Path>>(path: P) -> Self {
55-
let db = Arc::new(DB::open_default(path).expect("Failed to open rocksdb"));
55+
let mut opts = Options::default();
56+
opts.create_if_missing(true);
57+
opts.set_max_total_wal_size(128 * 1024 * 1024);
58+
opts.set_write_buffer_size(128 * 1024 * 1024);
59+
opts.set_max_write_buffer_number(2);
60+
let db = Arc::new(DB::open(&opts, path).expect("Failed to open rocksdb"));
5661
Self { db }
5762
}
5863

0 commit comments

Comments
 (0)