All articles
Storage & coordinationDesign analysis

VelarixDB: A Novel Database Tackling the Challenge of IO Amplification

Preface

Almost all databases are uvicorn, having at least or at most one special unique competitive edge, which is named the ‘branding edge’. In the modern corporation service market, which is dominated by all-purpose databases like pgsql and mysql, this ‘branding edge’ is the living basis for most companies. And in many cases, this ‘branding edge’ should be directly visible to users, telling people that there are something I can complete better and faster than any other choices. For example, elasticsearch’s plentiful feature set in text-search scenarios and also comprehensive tool stream in handling log data enable ES lead the market of enterprise log data storage. Also, PouchDB runs inside a browser and helps web developers to store data locally. These storage engines provide special characters that are directly accessible by users. However, very interestingly, I ran across a very young Database, which is not positioned not by its function features, but by its solution to a persistent technical issue. This essay is written to introduce this young database: VelarixDB

Product positioning

VelarixDB addresses KV storage, a fiercely competitive market. But compared to LevelDB and RocksDB, Velarix DB is designed to solve a very influential technical problem: Read&&Write Amplification, resulting in better performance and durability for storage devices.

Backgroud knowledge: IO Amplification, Compaction Cascading

IO Amplification:

For all LSM-based storage engines, io amplification is an inescapable issue. This is mainly because of two points:

  1. Deletion and updates is not applied on place, compaction is needed to truly remove junk data and save storage space.
  2. The generation of data files is controlled by user behaviour to a certain extent, which may produce many data files in various sizes. And excessive small, fragmented files can severely hinder query efficiency. This problem is also addressed by compaction.

But in the process of compaction, DB has to read needed data into memory, converting data into in-memory data structure, doing some data computation and movements, and finally write all generated data back into the disk. So throughout the lives of most data, they will be written and read from disks many times. This is a very costly shortage of LSM structure, not only consuming too many iops of storage devices, but also badly influencing the stability of database system and drasitically reduce the lifespan of hardware devices.

Core resolution of VelarixDB:

VelarixDB‘s resolution to the IO amplification is: separating keys from values and using offsets instead. In this way, the amount of data involved in compaction is minimized, which directly reduces the risk of triggering further compactions in subsequent levels. This approach effectively reduces the compaction cascading effect, leading to more efficient compactions and less wear on storage devices.

So, why separating keys and values can markedly reduce IO amplification?

Let’s see the diagram as following.

Figure 1View full-size image

When storing keys and values together, values may be strings in various lengths. In the case as above, five value strings are totally 40 bytes in size, and all these 40 bytes have to be read into memory but not used in the process of compaction at all, due to the fact that compaction involve only keys, not values.

Figure 2View full-size image

But if separating keys and values as the diagram above, when doing compaction for these two sstables, only 5 int32 offsets are read into the memory and the data files storing value strings are not involved in the process. So the sum of bytes are read is only 5*4=20 bytes. Compared to former case, the IO cost reduce by 50%. Considering long values stored like long text, the benefits brought by this reduction in I/O costs will be very significant. And also, as the overall size of sstables only includes keys and offsets, it become greatly less frequent for sstables in one level to trigger one more further compaction. So compaction cascading will be mitigated effectively and IO amplification will be reduced notably.

Perf benefits based on this design

According to the benchmarks presented in the WiscKey paper, implementations can outperform LevelDB and RocksDB by:

2.5x to 111x for database loading

1.6x to 14x for random lookups

Well, it seems that perf benefit is very apparent, but there’s one further more question.

Why random queries can also improve by separating key-value storages?

The most obvious shortage of separating keys and values is that the system has to trigger one more IO operation when trying to access values because at the first time of retrieval, only offsets are got! It’s unavoidable to fetch values using these offsets involved. So intuitively, random query’s perf will be influenced negatively but velarixDB announce their random queries are also markedly faster than levelDB. Considering this question, I guess the main reasons are as following:

  1. Higher key density: as sstable files storing keys and offsets are much smaller than before, so the system can hold a lot more keys in the memory. This will markedly reduce the levels involved in the query process and save much time for loading data from disk.
  2. Enable high parallel of SSD read: as the stored offsets are all fixed size int32s, so the system can very well harness interal parallelism in SSDs. And according to their document:

for request size ≥ 64KB, the aggregate throughput of random reads with 32 threads matches the sequential read throughput.

This internal concurrency mechanism can achieve good performance close to sequential reads. Random queries benefit from this a lot too.

Further optimization introduced

Besides separating keys and values, some other optimization are also introduced including:

  1. BloomFilter for in-memory key search
  2. Min-max range in SST
  3. SST index

So for any single input random query in VelarixDB, it’s highly possible to be filtered by BloomFilter and min-max range for SST, and finally be searched using internal index. As much more keys sstables can be loaded into memory, this multi-level index mechanism can maximize the benefit of separation of keys and values.

Final words

After a cursory reading of VelarixDB’s documentation and code, I am very impressed by the courage and determination of the team behind it in tackling technical challenges. All engineers who dare to try are brave pioneers. Also, I am very honored to be the 10th person to star it in github. I hope VelarixDB can find a solid market niche and achieve sustainable commercial success.

Good Luck!

— MrPresent-Han