Skip to content

feat(rocksdb): add memory limit configuration options#302

Open
frperezr wants to merge 3 commits intocozodb:mainfrom
frperezr:feat/block-cache-size
Open

feat(rocksdb): add memory limit configuration options#302
frperezr wants to merge 3 commits intocozodb:mainfrom
frperezr:feat/block-cache-size

Conversation

@frperezr
Copy link
Copy Markdown

@frperezr frperezr commented Dec 31, 2025

Summary

Add RocksDB memory configuration options to prevent unbounded memory growth:

  • block_cache_size: Limit LRU block cache (read cache)
  • write_buffer_size: Size per memtable
  • max_write_buffer_number: Max concurrent memtables
  • db_write_buffer_size: Total memtable memory budget

Motivation

Without these limits, RocksDB can consume all available memory during heavy write workloads, leading to OOM kills on containers.

Usage

{
  "block_cache_size": 2147483648,
  "write_buffer_size": 67108864,
  "max_write_buffer_number": 4,
  "db_write_buffer_size": 536870912
}

Add support for configuring RocksDB's block cache size through the
options JSON parameter when creating a database with the rocksdb engine.

Changes:
- Add block_cache_size setter to DbBuilder (cozorocks)
- Fix bug: use actual block_cache_size value instead of hardcoded 1GB
- Fix bug: apply cache to default options, not just when options_path exists
- Fix bug: preserve cache when bloom_filter is enabled
- Add RocksDbOpts struct and new_cozo_rocksdb_with_opts function
- Parse block_cache_size from JSON options in DbInstance::new

Usage:
  DbInstance::new("rocksdb", "/path/to/db", "{\"block_cache_size\": 2147483648}")

This allows users to control memory usage by limiting the block cache,
preventing unbounded memory growth during large ingestion workloads.
Add three new RocksDB options to limit memory usage:
- write_buffer_size: size of each memtable (default 64MB)
- max_write_buffer_number: max concurrent memtables (default 2)
- db_write_buffer_size: total memory budget for all memtables

These options help prevent unbounded memory growth during
heavy write workloads like bulk ingestion.
@frperezr frperezr changed the title feat(rocksdb): add configurable block_cache_size option feat(rocksdb): add memory limit configuration options Dec 31, 2025
…ilter enabled

When use_bloom_filter is true, BlockBasedTableOptions was created without
cache_index_and_filter_blocks=true, causing index and filter blocks to be
stored outside the block cache and grow unbounded.

Copy the essential settings from default_db_options() to ensure consistent
behavior regardless of bloom filter configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant