[Enhance]: FTS RocksDB column families get 128 MiB x 6 write buffers with no global cap

Đang mở
#783 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@iaojnh đang làm issue này rồi.

Từ ngày 21/10/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

Affected Component

RocksDB options for the FTS index and the ID map (RocksdbContext::prepare_options, src/db/common/rocksdb_context.cc)

Current Behavior

On main (53c1bb6):

  • prepare_options() calls OptimizeLevelStyleCompaction() with its default 512 MiB memtable budget (rocksdb_context.cc:247). This sets every column family of every RocksDB instance to write_buffer_size = 128 MiB and max_write_buffer_number = 6.
  • The only override is write_buffer_size = 8 << 20 (8 MiB), and it applies only when a DB-wide merge_op is passed (rocksdb_context.cc:271-275). The FTS index registers per-CF merge operators and passes merge_op = nullptr (src/db/index/column/fts_column/fts_indexer.cc:71-72, :75-77; src/db/index/segment/segment_helper.cc:1042-1044), so FTS column families keep 128 MiB. The ID map also passes no merge operator (src/db/index/common/id_map.cc:36, :42).
  • A writable FTS index has 5 column families per FTS field, plus $FTS_STAT and default (fts_indexer.cc:50-65). That makes 7 column families for one field and 12 for two.
  • Nothing bounds the total across column families or DBs: write_buffer_manager = nullptr (rocksdb_context.cc:286-287) and db_write_buffer_size = 0.
  • Every FTS column family uses a HashSkipList memtable with 1,000,000 buckets (rocksdb_context.cc:295-305), which is an 8 MB bucket array per memtable. Read-only opens use it too.
  • Each DB creates a rocksdb::Statistics object (rocksdb_context.cc:283-284). Nothing under src/ reads it. This is minor and we did not measure it.

Standalone check, with zvec 0.7.0 from PyPI (rocksdb_context.cc is identical in v0.7.0 and 53c1bb6):

# python fts_memtables.py 0|1|2   (number of FTS fields)
import glob, os, re, sys, tempfile
import zvec
from zvec import CollectionOption, CollectionSchema, DataType, Doc, FieldSchema, FtsIndexParam

def rss_anon_mb():
    return next(int(l.split()[1]) // 1024 for l in open("/proc/self/status") if l.startswith("RssAnon:"))

n_fts = int(sys.argv[1])
schema = CollectionSchema(name="fts", fields=[FieldSchema("v", DataType.INT64)] + [
    FieldSchema(f"t{i}", DataType.STRING, index_param=FtsIndexParam(tokenizer_name="standard"))
    for i in range(n_fts)])
path = os.path.join(tempfile.mkdtemp(), "c")

base = rss_anon_mb()
coll = zvec.create_and_open(path=path, schema=schema,
                            option=CollectionOption(read_only=False, enable_mmap=True))
print(f"{n_fts} FTS field(s): create_and_open  RssAnon +{rss_anon_mb() - base} MB")
coll.insert([Doc(id=str(i), fields={"v": i, **{f"t{j}": f"hello {i}" for j in range(n_fts)}})
             for i in range(100)])
coll.flush()
del coll

base = rss_anon_mb()
coll = zvec.open(path=path, option=CollectionOption(read_only=True, enable_mmap=True))
print(f"{n_fts} FTS field(s): open read-only   RssAnon +{rss_anon_mb() - base} MB")

for opts in sorted(glob.glob(f"{path}/*/fts.*/OPTIONS-*"))[-1:]:
    text = open(opts).read()
    print("column families:", len(re.findall(r"^\[CFOptions ", text, re.M)))
    for key in ("write_buffer_size", "max_write_buffer_number", "db_write_buffer_size", "bucket_count"):
        print(" ", sorted(set(re.findall(rf"\b{key}=(\d+)", text))), key)
0 FTS field(s): create_and_open  RssAnon +2 MB
0 FTS field(s): open read-only   RssAnon +0 MB
1 FTS field(s): create_and_open  RssAnon +57 MB
1 FTS field(s): open read-only   RssAnon +46 MB
column families: 7
  ['134217728'] write_buffer_size
  ['6'] max_write_buffer_number
  ['0'] db_write_buffer_size
  ['1000000'] bucket_count
2 FTS field(s): create_and_open  RssAnon +95 MB
2 FTS field(s): open read-only   RssAnon +92 MB
column families: 12
  ['134217728'] write_buffer_size
  ['6'] max_write_buffer_number
  ['0'] db_write_buffer_size
  ['1000000'] bucket_count

Measured write path, in an application that flushes every 64 docs. This run was its full rebuild, which writes one collection with a single flush at the end: 10,785 English paragraphs, two FTS fields (standard and ngram tokenizers) and a 1024-dim fp32 HNSW field. The library was zvec 1ab7975 from the zvec-rust 0.7.2 prebuilt. We changed the constants by patching immediates in the prebuilt libzvec_c_api.so, which affects every RocksDB instance in the process. Peak RSS is VmHWM, 2 rounds per arm with the arm order rotated:

Arm Peak RSS (round 1 / round 2) Write-phase wall time (round 1 / round 2)
Stock 1,103 MB / 1,165 MB 73.8 s / 68.7 s
bucket_count 16,384 740 MB / 782 MB 95.1 s / 83.2 s
bucket_count 16,384 and memtable budget 32 MiB (write_buffer_size 8 MiB) 357 MB / 360 MB 56.9 s / 58.8 s
  • The 32 MiB budget also changes target_file_size_base (to 4 MiB) and max_bytes_for_level_base (to 32 MiB). The collection had 27 SSTs instead of 18, with the same total SST bytes (57.6 MB).
  • We did not control the timings for host load, so treat them as indicative only.
Desired Improvement
  1. Give FTS (and ID-map) column families an explicit, small write_buffer_size and a lower max_write_buffer_number. One way is to apply the existing 8 MiB setting whenever per_cf_merge_ops is non-empty, not only when a DB-wide merge_op is set. Another is to call OptimizeLevelStyleCompaction() with a budget sized for these small DBs.
  2. Keep a process-wide bound on memtable memory. Open PR #770 does this with a shared WriteBufferManager and block cache, and derives the HashSkipList bucket count from its budget. On the 16 GiB host above, its default budget works out to about 1.9 GiB for RocksDB: 15% of 0.8 × host memory. That is above the 1.1 GB peak we measured, so the per-CF size in point 1 still decides the write-path peak. We left details on the bucket sizing as a comment on #770.
  3. Minor: create rocksdb::Statistics only when asked for. It is still created per DB in #770.
Impact
  • Lower and more predictable memory per writable collection. In the measurement above, peak RSS for the same write fell from 1,103–1,165 MB to 357–360 MB when both the bucket count and the write buffer size were reduced.
  • Each FTS column family would no longer hold up to 6 × 128 MiB of memtables, so memory would scale less with the number of FTS fields and open collections.
Ngôn ngữ chính
C++
Star
16.3k
Fork
1k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
32

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của alibaba/zvec

Tất cả issue của alibaba/zvec

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.