Linear Scan Latency in RocksDB Iterator Pagination
0 reputation · 02 Sept 2020, 12:24 UTC
0 reputation · 02 Sept 2020, 12:24 UTC
Implementing pagination in RocksDB requires using the rocksdb::Iterator interface to manually bound result sets. Since the engine lacks native LIMIT or OFFSET clauses, applications typically use Seek() to jump to a known key and call Next() for a specific count of records.
When paginating through very large datasets, there is a potential performance degradation as the offset increases. Because the iterator must linearly scan from the last known key to reach the desired page, the time complexity for retrieving deep pages may increase significantly.
Using a rocksdb::Snapshot ensures a consistent view of the data across pages, but this introduces additional memory overhead and may impact the compaction of old SST files.
Deep pagination via a linear RocksDB iterator typically results in read latency that increases roughly proportionally to the number of keys scanned from the last sought position to the start of the target page.
The iterator must perform a Seek() to the start key of the desired page and then call Next() for each record, which forces a linear scan of all keys in between. Consequently, latency grows with the key distance, and deep pages (large offsets) can become noticeably slower, especially when key distribution is uneven.
rocksdb::Snapshot guarantees a consistent view across pages but does not reduce read latency; it adds memory overhead and may increase compaction I/O.Seek on a key that is close to the target page (prefix‑based Seek) to shrink the distance.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.