kraret / pub-task Goto Github PK
View Code? Open in Web Editor NEWTerark public developing
License: MIT License
Terark public developing
License: MIT License
When MemTableRep::MarkReadOnly()
, we should do something like vector::shrink_to_fit()
to free unused extra memory. since we use large memory block, the unused memory is the upper part of the
memory block.
Such memory block can be shrinked by realloc
, but realloc
is not guaranteed to shrink memory in place. This is not an issue in single thread, but it is a big issue in multi-thread:
realloc
, and realloc
reallocated a smaller memory block and copying old memory into the smaller memory block, then free
the old memory block.A good news is that jemalloc
has a specific function xallocx
:
// jemalloc specific:
size_t xallocx(void *ptr, size_t size, size_t extra, int flags);
The xallocx()
function resizes the allocation at ptr
in place to be at least size
bytes, and returns the real size of the allocation. If extra
is non-zero, an attempt is made to resize the allocation to be at least (size + extra)
bytes, though inability to allocate the extra
byte(s) will not by itself result in failure to resize. Behavior is undefined if size
is 0, or if (size + extra > SIZE_T_MAX)
.
The realloc()
, rallocx()
, and xallocx()
functions may resize allocations without moving them under limited circumstances. Unlike the allocx()
API, the standard API does not officially round up the usable size of an allocation to the nearest size class, so technically it is necessary to call realloc()
to grow e.g. a 9-byte allocation to 16 bytes, or shrink a 16-byte allocation to 9 bytes. Growth and shrinkage trivially succeeds in place as long as the pre-size and post-size both round up to the same size class. No other API guarantees are made regarding in-place resizing, but the current implementation also tries to resize large allocations in place, as long as the pre-size and post-size are both large. For shrinkage to succeed, the extent allocator must support splitting (see arena.<i>.extent_hooks). Growth only succeeds if the trailing memory is currently available, and the extent allocator supports merging.
realloc
, shrink is in place when the memory block is large
, the large
defined in jemalloc is really small
for our usage, we can define our large
value larger to get stronger guarantee, such as 2M
.This memory pool is aimed to showing advantages of our MemTable refactory:
Using array based Threaded Red-Black Tree:
struct Node {
uint32_t left;
uint32_t right;
uint64_t offset : 39; // offset to key value data in mempool
uint64_t color : 1; // red or black
uint64_t keylen : 24; // valuelen = offset[idx+1] - offset.nodes[idx] - keylen;
};
232 - 2
224-1
Now NestLoudsTrie
support user provided memory and do not use malloc. terark-zip-table
should speed up by this feature.
MemPool_CompileX
.Keys in rocksdb are SST often range-clustered, say that range overlap points in different SST across level are rare.
Pick several sorted runs, then Create an index to map key range into SST number, we call this is a light weight compaction.
With file read+write mmap memory pool, write to device will not introduce cpu&memory waste.
This needs RocksDB to create a file for memtable.
If the memory pool file is in NVM, this will produce a non-volatile memtable.
This improvement is less useful for distributed rocksdb.
In compaction, TerarkSST needs two pass scan, now we require two pass scan yield identical result, this restriction can be removed: just keep the intersection set of these two pass scan!
TerarkDB 的反向扫描很快,我们需要拿出测试结果。
对比项目:
Iterator.Seek
,接着执行若干次(10次,20次…) Iterator.Prev
parent
mutex sharded by 127
, because:
x % 127
can be optimized by compilerNow mmap data is madvised as RANDOM, random is not optimal for index data, such as NLT & zbs offsets.
在 WriteBatchWithIndex 中,每个 ColumnFamily 一个 Index,以减少 compare 的开销,提高总体性能。
In rocksdb, add a callback for db to notify db changes to application.
For example, in MyRocks, if MyRocks storage engine has states
, and these states
is used as cache for some metadata.
In distributed MyRocks, slave node read wal-log to sync master's change on db, thus the states
for metadata cache may be staled. By db-change callback, these states
can be updated.
This can also be implemented by slaver's wal-log syncer.
We can not find an optimized dynamic Patricia Trie implementation, so we write it ourselfves.
This Patricia Trie will be use as rocksdb memtable.
投机执行写出的 value 文件,目前在投机失败时会被丢弃,将这些数据利用起来,减小第二遍扫描的数据量
As described in RocksDB issue
This is a low priority job of us, let RocksDB community to grab it first.
find a byte which does not exist in core string, use this byte as end mark.
The core string vector will be sorted by right-aligned bytewise order(longer is less) for compressing and use the end mark.
对 core string vector 进行排序:依据右对齐的字节序,即从字符串末尾开始往前进行比较,长串更小:
int compare(fstring x, fstring y) {
size_t n = std::min(x.size(), y.size());
auto px = (const byte_t*)x.data() + x.size();
auto py = (const byte_t*)y.data() + y.size();
while (n) {
if (*--px != *--py)
return *px < *py ? -1 : +1;
--n;
}
if (x.size() > y.size()) return -1; // longer is less 长的更小
if (x.size() < y.size()) return +1; // shorter is greater
return 0;
}
investigate the feasibility of mixing fuse + mmap
and libgfapi glfs_pread
There are two kind of readonly readers, syncing-readonly
and nonsyncing-readonly
.
Writer
publish DB changes: wal-log, manifest...syncing-readonly
, it subscribe topics for DB changesnonsyncing-readonly
, it just do read2018-10-18 10:57
: In gluster-env implementation, create a sync-channel for log files: file name pattern is log, we create such a sync-channel, this may be simplify the overall implementation.Divide large NLT into blocks, to improve sequencial scan performance.
PatriciaTrie based MemTable can be dumped to disk and load by mmap, yield many andvantages:
Dump MemTable is much faster than MemTable flush, yield many andvantages:
writer/master
may delete file if not needed any more, so it must "know" files in using by reader/slave
For future feature DB::Prefetch(begin, end)
, which can be used by MyRocks...
Now rocksdb has Factory for MemTable classes, but it lacks Abstract Factory
, we can not create a MemTable just by class name.
So add Abastract Factory by MemTable class name.
Now terark_zip_table has zvType
, but we don't know GroupSize
of each MultiValue
pack before unzip it. To get GroupSize
before unzip with succinct:
rank0, rank1, rank2, rank3
zvType
GroupSize
in a separated arrayHigh level code:
size_t groupIndex = zvType.rank3(recId); // 3 == ZipValueType::kMulti
groupSize = groupSizeVec[groupIndex];
// ....
After building outer trie, the inner strVec maybe fixed length, or nearly fixed length, we can save the fixed length suffix into an parallel array, thus omit the storage for offset array.
Use Thead Local Cache to minimize CPU Cache conflict.
2M block for sfree
implementation:
void sfree(size_t pos, size_t len) {
auto tc = m_thread_cache[pos >> 21]; // >>21 for div 2M
tc->sfree(pos, len);
}
dynamic patricia trie should be fast, but it is hard to implement concurrent write, so using prefix id to multiplex writes.
use gluster native api, do not use gluster fuse
mmap
for reading index dataHas added RandomAccessFile::FsRead
for this purpose: d1d5621a
Implement such a memtable is to using hint
to optimize sequential writes.
hint
should be end()
, boost intrusive rbtree packed color bit into pointer, and it has parent
point, which is why it can be optimized by hint
. rbtree without parent
pointer is very hard to optimize by hint
.
Create an instance-thread-local
Sub-MemTable
for such MemTable
, such MemTable
is optimized for write and has read amplification.
KeyValue
into its Sub-MemTable
We first implement such MemTable
on top of PatriciaTrie
realloc
to shrink_to_fit
, we assume realloc
will not relocate memory when shrink.
xallocx
which is dedicated for resize memory in placeOnce MemTable is not a bottle neck, the advantage of distributed compaction will be shown more...
Use wikipedia data, multi thread/connection.
Uniform random read:
Write:
如果 glusterfs 的 tailing 性能足够强,我们就不需要 ZeroMQ 之类的消息系统来同步 WAL Log。
tail 测试在一个结点上追加写文件,在另一个结点上读文件末尾。glusterfs 自带 tail 命令,其使用 glusterfs 的用户层 API 实现,效率要高于在 fuse 上挂载并使用 linux tail 命令。
可能需要自己写代码,着重测试 tail 延时。
Merge multi levels into one, use cut-point index to dispatch queries into real SST.
map zip-content are as nvm-page-cache-by-pass,other area as normal mmap.
For DictZipBlobStore.
in 1-write n-read framework, write node just handling client write request and sst flush.
background compactions are running on other nodes, once compaction finished, notify all nodes to update: load new sst and discard old sst.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.