Deterministic memory usage of RocksDB.
I have observed in some tests that memory consumption of RocksDB increases as DB size grows.
- Does RocksDB use memory deterministically ?
- Is memory consumption expected to increase over time even when the flag "cache_index_and_filter_blocks = true" ?
- 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.
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 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 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".
@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 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!
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.
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
Hi @igorcanadi , Is there a single function call that would return the total memory in use by rocksDB?
@ashwin95r Check out @yhchiang's previous comment -- GetApproximateMemoryUsageByType.
I'm closing this issue since it seems like the original question has been resolved.