Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rocksdb out of memory

I'm trying to find out why my kafka-streams application runs out of memory. I already found out that rocksDB is consuming lots of native memory and I tried to restrict it with the following configuration:

# put index and filter blocks in blockCache to avoid letting them grow unbounded (https://github.com/facebook/rocksdb/wiki/Block-Cache#caching-index-and-filter-blocks)
cache_index_and_filter_blocks = true;

# avoid evicting L0 cache of filter and index blocks to reduce performance impact of putting them in the blockCache (https://github.com/facebook/rocksdb/wiki/Block-Cache#caching-index-and-filter-blocks)
pinL0FilterAndIndexBlocksInCache=true

# blockCacheSize should be 1/3 of total memory available (https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#block-cache-size)
blockCacheSize=1350 * 1024 * 1024

# use larger blockSize to reduce index block size (https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide#difference-of-spinning-disk)
blockSize=256 * 1024

but still the memory usage seems to grow unbounded and my container eventually gets OOMKilled.

I used jemalloc to profile the memory usage (like described here) and the result clearly shows that rocksDB is responsible but I have no clue how to further restrict the memory usage of rocksDB.

jemalloc profiling

I don't know if it is helpful, but for completeness here are statistics gathered from a running rocksdb instance:

rocksDB statistics

I'm glad for any hints

like image 402
D-rk Avatar asked Jun 19 '19 08:06

D-rk


People also ask

Is RocksDB a memory?

RocksDB Architecture memtable: an in-memory data-structure to ensure very low latency on reads. sorted static table files (SST files): where data is finally persisted.

Is RocksDB a cache?

The non-volatile cache is officially referred to in RocksDB as the SecondaryCache. By maintaining a SecondaryCache that's an order of magnitude larger than DRAM, fewer reads would be required from remote storage, thus reducing read latency as well as network bandwidth consumption.

What is block cache in RocksDB?

Block cache is where RocksDB caches data in memory for reads. User can pass in a Cache object to a RocksDB instance with a desired capacity (size). A Cache object can be shared by multiple RocksDB instances in the same process, allowing users to control the overall cache capacity.


1 Answers

Are you seeing the memory usage grow quickly or over a longer period of time?

We have found and fixed a few RocksDB resource leaks that would cause memory leaks:

  • BloomFilters can leak (https://issues.apache.org/jira/browse/KAFKA-8323) This was fixed in 2.2.1 and (pending 2.3.0)
  • Custom RocksDB configs are doomed to create leaks (https://issues.apache.org/jira/browse/KAFKA-8324) This will be fixed in 2.3.0

There are some indications that there may be others (https://issues.apache.org/jira/browse/KAFKA-8367), either in our usage of RocksDB or in RocksDB itself.

Oh, one other idea is that if you're using iterators from the state stores, either in your processors or in Interactive Query, you have to close them.

Beyond looking for leaks, I'm afraid I don't have too much insight into diagnosing RocksDB's memory usage. You could also restrict the Memtable size, but I don't think we set it very large by default anyway.

Hope this helps,

-John

like image 139
John Avatar answered Sep 28 '22 18:09

John