Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding KeyValue embedded datastore vs FileSystem

I have a basic question with regards to FileSystem usage I want to use a embedded KeyValue store, which is very write oriented. (persistent) Say my value size is a) 10 K b) 1 M and read and updates are equal in number

Cant I simply create files containing the value and there name acting as keys.

Wont it as fast as using a KeyValue store as LevelDB or RocksDB.

Can anybody please help me understand .

like image 305
Rajesh Gaur Avatar asked Sep 07 '14 23:09

Rajesh Gaur


1 Answers

In principle, yes, a filesystem can be used as a key-value store. The differences only come in when you look at individual use cases and limitations in the implementations.

Without going into too much details here, there are some things likely to be very different:

  • A filesystem splits data into fixed size blocks. Two files can't typically occupy parts of the same block. Common block sizes are 4-16 KiB; you can calculate how much overhead your 10 KiB example would cause. Key/value stores tend to account for smaller-sized pieces of data.
  • Directory indexes in filesystems are often not capable of efficiently iterating over the filenames/keys in sort order. You can efficiently look up a specific key, but you can't retrieve ranges without reading pretty much all of the directory entries. Some key/value stores, including LevelDB, support efficient ordered iterating.
  • Some key/value stores, including LevelDB, are transactional. This means you can bundle several updates together, and LevelDB will make sure that either all of these updates make it through, or none of them do. This is very important to prevent your data getting inconsistent. Filesystems make this much harder to implement, especially when multiple files are involved.
  • Key/value stores usually try to keep data contiguous on disk (so data can be retrieved with less seeking), whereas modern filesystems deliberately do not do this across files. This can impact performance rather severely when reading many records. It's not an issue on solid-state disks, though.
  • While some filesystems do offer compression features, they are usually either per-file or per-block. As far as I can see, LevelDB compresses entire chunks of records, potentially yielding better compression (though they biased their compression strategy towards performance over compression efficiency).
like image 93
Jan Krüger Avatar answered Oct 23 '22 20:10

Jan Krüger