Search code examples
cachingmemcachedrocksdb

Usability of RocksDB for caching services


I've read mostly English papers and manuals and my native language is not English, that's why I don't understand quite a lot about how RocksDB works. Can you answer me a couple of questions about how RocksDB works, please?

  1. Is RocksDB single threaded or multithreaded? Does it process all tasks in multithreaded mode? And how does it work? Does RocksDB have something like a load balancer that distributes tasks between different threads?

  2. What does RocksDB do in case if RAM memory does not have enough space for a new record? For example some of caching services delete least used information to be able to load a new record, some of them just report an out of memory error. And what does RocksDB do in that case?

  3. I compare Rocksdb and Memcached a lot, since I was looking for a caching service for a highly loaded website. For caching purpose, what would be the faster one? RocksDB or Memcached? I'v tried to find benchmarks but haven't found any.


Solution

  • 1). It is multi-threaded. It uses background threads to write data to disk and to maintain an efficient data layout on the disk (a log structured merge-tree - LSM). There isn't really a "tasks being processed" kind of thing, because it is a library you link into your process. Your process is then responsible for using it in a safe way, if it is multi-threaded.

    2). RAM is only used to cache data in rocksdb. Data is persisted into an efficient on-disk data structure - the aforementioned LSM. If your cache is full something will be evicted, but it is still on disk.

    3). Memcached is probably faster in most cases where you do a simple lookup, but since rocksdb is a library it can be used in many different ways they cannot really be compared. I know of one setup where rocksdb write its files to a RAMfs, which is of course much faster than to disk, but in the typical setup, I would expect that having to maintain the order of records and having to persist data will make it significantly slower than the RAM-based associative arrays memcached uses. If your main cost is the network-access to memcached, having a colocated rocksdb may be faster.