TerarkDB是字节跳动开源的 RocksDB的替代品,具有优化的尾部延迟、吞吐量和压缩等。在大多数情况下,你可以将现有的RocksDB实例迁移到TerarkDB,没有任何问题。
TerarkDB仅在Linux平台下测试和生产就绪除C/C++之外的语言绑定尚未完全测试。现有数据可以直接从RocksDB迁移到TerarkDB,但不能迁移回RocksDB。TerarkDB是从RocksDBv5.18.3分支出来的性能概览RocksDBv6.12服务器Intel(R)Xeon(R)Gold5218CPU@2.30GHz(2插槽,32核64线程)376GB动态内存NVMeTLC固态硬盘(3.5TB)工作台工具和工作负载利用 db_bench10个客户端线程,每个线程20GB请求键=24字节,值=2000字节heavy_write 意味着90%的写操作heavy_read 意味着90%的读取操作用法基于块的表(BlockBasedTable)#include<cassert>#include"rocksdb/db.h"rocksdb::DB*db;rocksdb::Optionsoptions;//Youroptionshereoptions.create_if_missing=true;options.wal_bytes_per_sync=32768;options.bytes_per_sync=32768;//OpenDBautostatus=rocksdb::DB::Open(options,"/tmp/testdb",&db);//Operationsstd::stringvalue;autos=db->Put(rocksdb::WriteOptions(),"key1","value1");s=db->Get(rocksdb::ReadOptions(),"key1",&value);assert(s.ok());assert("value1"==value);s=db->Delete(rocksdb::WriteOptions(),"key1");assert(s.ok());或手动设置表格格式和表格选项:
#include<cassert>#include"rocksdb/db.h"#include"rocksdb/options.h"#include"rocksdb/table.h"rocksdb::DB*db;rocksdb::Optionsoptions;//Yourdboptionshereoptions.create_if_missing=true;options.wal_bytes_per_sync=32768;options.bytes_per_sync=32768;//Manuallyspecifytargettableandtableoptionsrocksdb::BlockBasedTableOptionstable_options;table_options.block_cache=rocksdb::NewLRUCache(32ULL<<30,8,false);table_options.block_size=8ULL<<10;options.table_factory=std::shared_ptr<rocksdb::TableFactory>(NewBlockBasedTableFactory(table_options));//OpenDBautostatus=rocksdb::DB::Open(options,"/tmp/testdb2",&db);//Operationsstd::stringvalue;autos=db->Put(rocksdb::WriteOptions(),"key1","value1");s=db->Get(rocksdb::ReadOptions(),"key1",&value);assert(s.ok());assert("value1"==value);s=db->Delete(rocksdb::WriteOptions(),"key1");assert(s.ok());Terark压缩表格(TerarkZipTable)#include<cassert>#include"rocksdb/db.h"#include"rocksdb/options.h"#include"rocksdb/table.h"#include"table/terark_zip_table.h"rocksdb::DB*db;rocksdb::Optionsoptions;//Yourdboptionshereoptions.create_if_missing=true;options.wal_bytes_per_sync=32768;options.bytes_per_sync=32768;//TerarkZipTableneeda`fallback`optionsbecauseyoucanindicatewhichLSMlevelyouwanttostartusingTerarkZipTable//Forexample,bysettingtzt_options.terarkZipMinLevel=2,TerarkDBwilluseyourfallbackTableonlevel0and1.std::shared_ptr<rocksdb::TableFactory>table_factory;rocksdb::BlockBasedTableOptionsblockbased_options;blockbased_options.block_size=8ULL<<10;table_factory.reset(NewBlockBasedTableFactory(blockbased_options));rocksdb::TerarkZipTableOptionstzt_options;//TerarkZipTablerequiresatempdirectoryotherthandatadirectory,aslowdeviceisacceptabletzt_options.localTempDir="/tmp";tzt_options.indexNestLevel=3;tzt_options.sampleRatio=0.01;tzt_options.terarkZipMinLevel=2;//StartusingTerarkZipTablefromlevel2table_factory.reset(rocksdb::NewTerarkZipTableFactory(tzt_options,table_factory));options.table_factory=table_factory;//OpenDBautostatus=rocksdb::DB::Open(options,"/tmp/testdb2",&db);//Operationsstd::stringvalue;autos=db->Put(rocksdb::WriteOptions(),"key1","value1");s=db->Get(rocksdb::ReadOptions(),"key1",&value);assert(s.ok());assert("value1"==value);s=db->Delete(rocksdb::WriteOptions(),"key1");assert(s.ok());实际性能改进TerarkDB已经部署在字节跳动的许多应用程序中,在大多数情况下,TerarkDB可以帮助减少延迟峰值并极大地提高吞吐量。
磁盘写入(DiskWrite)
获取延迟(GetLatency )
评论