RocksDB开发——环境准备

RocksDB编译运行

  • 环境:CentOS 7.6
  • gcc 4.8+ C++11

环境准备

安装git

需要从github拉去源码

    yum install git

安装RocksDB所需要的依赖

  • 安装g++,确保g++版本足够新
	 yum install gcc48-c++
	 g++ --version
  • 安装gflags
    git clone https://github.com/gflags/gflags.git
    cd gflags
    git checkout v2.0
    ./configure && make && sudo make install

gflags默认安装时,include文件在/usr/local/include/gflags中,lib路径为/usr/local/lib,需要把这两个添加到环境变量

修改/etc/profile文件
source /etc/profile 生效

    #gcc找到头文件的路径
    C_INCLUDE_PATH=/usr/local/include/gflags
    export C_INCLUDE_PATH
    #g++找到头文件的路径
    CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/gflags
    export CPLUS_INCLUDE_PATH
    #找到动态链接库的路径
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    export LD_LIBRARY_PATH
  • 安装snappy:
   sudo yum install snappy snappy-devel
  • 安装zlib:
    sudo yum install zlib zlib-devel
  • 安装bzip2:
    sudo yum install bzip2 bzip2-devel
  • 安装lz4:
    sudo yum install lz4-devel
  • 安装ASAN(可选用于调试):
    sudo yum install libasan
  • 安装zstandard:
   wget https://github.com/facebook/zstd/archive/v1.1.3.tar.gz
   mv v1.1.3.tar.gz zstd-1.1.3.tar.gz
   tar zxvf zstd-1.1.3.tar.gz
   cd zstd-1.1.3
   make && sudo make install
   (make -j4) 可以加-j加速

编译rocksdb

源码连接 https://github.com/facebook/rocksdb
https拉取代码

    git clone https://github.com/facebook/rocksdb.git
    make -j4

编译测试工具db_bench

db_bench是测试RocksDB性能的主要工具。RocksDB从LevelDB继承了db_bench,并扩展了其功能以支持更多的功能

  • 在rocksdb目录下执行
    make db_bench -j4

测试 启动一个简单的benchmarks

    [root@localhost rocksdb]# ./db_bench --benchmarks="fillseq"
    Initializing RocksDB Options from the specified file
    Initializing RocksDB Options from command-line flags
    RocksDB:    version 6.2
    Date:       Mon May  6 08:14:45 2019
    CPU:        2 * Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
    CPUCache:   6144 KB
    Keys:       16 bytes each
    Values:     100 bytes each (50 bytes after compression)
    Entries:    1000000
    Prefix:    0 bytes
    Keys per prefix:    0
    RawSize:    110.6 MB (estimated)
    FileSize:   62.9 MB (estimated)
    Write rate: 0 bytes/second
    Read rate: 0 ops/second
    Compression: Snappy
    Compression sampling rate: 0
    Memtablerep: skip_list
    Perf Level: 1
    WARNING: Assertions are enabled; benchmarks unnecessarily slow
    ------------------------------------------------
    Initializing RocksDB Options from the specified file
    Initializing RocksDB Options from command-line flags
    DB path: [/tmp/rocksdbtest-0/dbbench]
    fillseq      :       7.854 micros/op 127328 ops/sec;   14.1 MB/s

你可能感兴趣的:(RocksDB)