Why is the latency fluctuation of iterators so huge?

71 views
Skip to first unread message

Aurora Twinkle

unread,
Nov 26, 2024, 5:50:25 AM11/26/24
to rocksdb

Hi, All:

I'm using rocksdb at work and I'm finding that the latency of my Iterator fluctuates wildly. I hope to get your help.(For more details, please refer to the screenshots. Some logs of rocksdb can be viewed in the attachments.)

My write tps is 6k/sec. The iterator operation is executed once per second, and all keys prefixed with the current timestamp (in seconds) are traversed. Usually 6k kv objects can be traversed per second. The p90 time of the iterator is basically within 500ms, but the p99 time often exceeds 500ms, which is unacceptable to me. Is there any way to improve the performance of iterators and reduce time consumption?

Machine Configuration:

8C32GB

disk: Enhanced SSD, Max throughput (MB/s): 350, Random IOPS:50000

RocksDB Configuration: 

writeBufferSize: 256MB

maxwriteBufferNumber:6

maxBackgroundJobs:100

Key format:

The key consists of a second-level timestamp plus a uuid, for example:

1732573201#3070f948-b2e7-4c4a-921a-06a3df033dc2

pseudocode: (System.currentTimeMillis() / 1000 + ThreadLocalRandom.current().nextInt(10, 3600)) + ”#” + UUID.randomUUID().toString()

Value:

The value is a randomly generated string of size 2kb

企业微信截图_42afbd2a-f440-46ce-9f97-a799c01b29a1.png
企业微信截图_1f83ed1d-3a52-49be-b2b6-b9b37aa95112.png
OPTIONS-265812
企业微信截图_fe37d7eb-7067-4a9a-ad31-a60ae6beb007.png
企业微信截图_c34a5640-9bd9-4a50-bb36-58ed94904188.png
企业微信截图_09b20b07-8b5d-4792-8b9e-117f209d38d4.png
企业微信截图_a49056af-39bb-43d0-9d55-2ca3d8f195d1.png
企业微信截图_4f7fd8e5-2fb2-4455-bd02-56f3f87276af.png

Aurora Twinkle

unread,
Nov 26, 2024, 5:53:50 AM11/26/24
to rocksdb
The java rocksdb version is: 8.11.4

Aurora Twinkle

unread,
Nov 26, 2024, 6:00:01 AM11/26/24
to rocksdb
The log fragment of rocksdb has been uploaded to the attachment. If more information is needed, I will provide it. And all startup configurations of rocksdb can be viewed in the attached OPTIONS-265812 file.

log.tar.gz
OPTIONS-265812

Ted Mostly

unread,
Nov 28, 2024, 1:33:04 AM11/28/24
to rocksdb

maybe you could reuse iterator and  `Refresh` it timely

one iteration per second may pin resource.

by WIKI

Resource pinned by iterators and iterator refreshing

Iterators by themselves don't use much memory, but it can prevent some resource from being released. This includes:

  1. memtables and SST files as of the creation time of the iterators. Even if some memtables and SST files are removed after flush or compaction, they are still preserved if an iterator pinned them.
  2. data blocks for the current iterating position. These blocks will be kept in memory, either pinned in block cache, or in the heap if block cache is not set. Please note that although normally blocks are small, in some extreme cases, a single block can be quite large, if the value size is very large.

So the best use of iterator is to keep it short-lived, so that these resource is freed timely.

An iterator has some creation costs. In some use cases (especially memory-only cases), people want to avoid the creation costs of iterators by reusing iterators. When you are doing it, be aware that in case an iterator getting stale, it can block resource from being released. So make sure you destroy or refresh them if they are not used after some time, e.g. one second. When you need to treat this stale iterator, before release 5.7, you'll need to destroy the iterator and recreate it if needed. Since release 5.7, you can call an API Iterator::Refresh() to refresh it. By calling this function, the iterator is refreshed to represent the recent states, and the stale resource pinned previously is released.

Aurora Twinkle

unread,
Dec 10, 2024, 2:50:35 AM12/10/24
to rocksdb
Thanks for the suggestion!
In this case, the iterator will be destroyed immediately after each use (usually the life cycle is only a few seconds), which should not cause resources to be unable to be released.
Reply all
Reply to author
Forward
0 new messages