rocksdb icon indicating copy to clipboard operation
rocksdb copied to clipboard

Deterministic memory usage of RocksDB.

Open lookforsandy opened this issue 11 years ago • 9 comments

I have observed in some tests that memory consumption of RocksDB increases as DB size grows.

  1. Does RocksDB use memory deterministically ?
  2. Is memory consumption expected to increase over time even when the flag "cache_index_and_filter_blocks = true" ?
  3. What are the major consumers of memory inside RocksDB ?

I am trying to find a way to keep the memory consumption of RocksDB constant even if DB grows eventually.

lookforsandy avatar Sep 02 '15 22:09 lookforsandy

Memory can be used by block cache (if cache_index_and_filter_blocks = true) as well as mem tables. You can track the later case by getting GetProperty() with property "rocksdb.size-all-mem-tables". Adding block cache size and this one is supposed to give you a pretty close estimation of memory usage (assuming you have cache_index_and_filter_blocks = true).

siying avatar Sep 02 '15 22:09 siying

@siying Thanks a lot for your response. Just to confirm again, say if I have 3 memtables each of 4M ; Block Cache of 128M ; and cache_index_and_filter_blocks = true. Does that mean RocksDB will never consume more than 140M (plus some memory for internal data structures) during its lifetime even if DB grows over time.

lookforsandy avatar Sep 02 '15 22:09 lookforsandy

@lookforsandy mostly, except if you have some stale iterators, they might pin down the old memetables from being released, increasing total memory usage. You can tell it by querying property "rocksdb.size-all-mem-tables".

siying avatar Sep 03 '15 00:09 siying

@lookforsandy I wrote a new wiki page that explains memory usage: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB

Let me know if it helps.

igorcanadi avatar Oct 19 '15 18:10 igorcanadi

@igorcanadi Thanks a lot for the wiki page. Can you please give some insight into the memory usage by compaction ? Is there a way (tunable) to limit the memory used (instantaneously) during the compaction ? Thanks!

lookforsandy avatar Dec 01 '15 02:12 lookforsandy

Compaction shouldn't affect memory usage too much. The only spike might be that for a short period of time we'll have both new and old index and bloom filters loaded. I can't think of anything else.

If you want to limit compaction size, you can reduce target_file_size to make files smaller.

igorcanadi avatar Dec 02 '15 21:12 igorcanadi

Btw, there's a new API GetApproximateMemoryUsageByType that reports different types of memory usage of a set of rocksdb instance. This might help you understand how rocksdb uses memory.

https://github.com/facebook/rocksdb/blob/master/include/rocksdb/utilities/memory_util.h#L35-L47

yhchiang avatar Dec 03 '15 19:12 yhchiang

Hi @igorcanadi , Is there a single function call that would return the total memory in use by rocksDB?

ashwin95r avatar Jun 27 '16 07:06 ashwin95r

@ashwin95r Check out @yhchiang's previous comment -- GetApproximateMemoryUsageByType.

I'm closing this issue since it seems like the original question has been resolved.

igorcanadi avatar Jun 27 '16 16:06 igorcanadi