Repository navigation
Conversation
facebook-github-bot
left a comment
There was a problem hiding this comment.
@sagar0 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@sagar0 has updated the pull request. View: changes, changes since last import |
a10bdc5 to
e6b7317
Compare
|
@sagar0 has updated the pull request. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@sagar0 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@sagar0 has updated the pull request. View: changes, changes since last import |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@sagar0 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@sagar0 has updated the pull request. View: changes, changes since last import |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@sagar0 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
1. Don't allocate a new buffer if the current buffer is sufficient for new data. This reduces one malloc + memcpy sequence. 2. Reduce a memmove by copying data directly from tail to the new buffer instead of doing a memmove + memcopy as earlier.
|
@sagar0 has updated the pull request. View: changes, changes since last import |
| &data_block_iter_, is_index_, | ||
| key_includes_seq_, | ||
| /* get_context */ nullptr, s); | ||
| /* get_context */ nullptr, s, prefetch_buffer_.get()); |
| buffer_.Alignment(alignment); | ||
| buffer_.AllocateNewBuffer(static_cast<size_t>(roundup_len), | ||
| copy_data_to_new_buffer, chunk_offset_in_buffer, | ||
| chunk_len); |
There was a problem hiding this comment.
May consider to add a little bit extra buffer to avoid another allocation if we have reached max readahead size.
There was a problem hiding this comment.
I'll defer this optimization for now; will get back to it.
|
@sagar0 has updated the pull request. View: changes, changes since last import |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@sagar0 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@sagar0 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: This PR extends the improvements in meta#3282 to also work when using Direct IO. We see **4.5X performance improvement** in seekrandom benchmark doing long range scans, when using direct reads, on flash. **Description:** This change improves the performance of iterators doing long range scans (e.g. big/full index or table scans in MyRocks) by using readahead and prefetching additional data on each disk IO, and storing in a local buffer. This prefetching is automatically enabled on noticing more than 2 IOs for the same table file during iteration. The readahead size starts with 8KB and is exponentially increased on each additional sequential IO, up to a max of 256 KB. This helps in cutting down the number of IOs needed to complete the range scan. **Implementation Details:** - Used `FilePrefetchBuffer` as the underlying buffer to store the readahead data. `FilePrefetchBuffer` can now take file_reader, readahead_size and max_readahead_size as input to the constructor, and automatically do readahead. - `FilePrefetchBuffer::TryReadFromCache` can now call `FilePrefetchBuffer::Prefetch` if readahead is enabled. - `AlignedBuffer` (which is the underlying store for `FilePrefetchBuffer`) now takes a few additional args in `AlignedBuffer::AllocateNewBuffer` to allow copying data from the old buffer. - Made sure not to re-read partial chunks of data that were already available in the buffer, from device again. - Fixed a couple of cases where `AlignedBuffer::cursize_` was not being properly kept up-to-date. **Constraints:** - Similar to meta#3282, this gets currently enabled only when ReadOptions.readahead_size = 0 (which is the default value). - Since the prefetched data is stored in a temporary buffer allocated on heap, this could increase the memory usage if you have many iterators doing long range scans simultaneously. - Enabled only for user reads, and disabled for compactions. Compaction reads are controlled by the options `use_direct_io_for_flush_and_compaction` and `compaction_readahead_size`, and the current feature takes precautions not to mess with them. **Benchmarks:** I used the same benchmark as used in meta#3282. Data fill: ``` TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=fillrandom -num=1000000000 -compression_type="none" -level_compaction_dynamic_level_bytes ``` Do a long range scan: Seekrandom with large number of nexts ``` TEST_TMPDIR=/data/users/$USER/benchmarks/iter ./db_bench -benchmarks=seekrandom -use_direct_reads -duration=60 -num=1000000000 -use_existing_db -seek_nexts=10000 -statistics -histogram ``` ``` Before: seekrandom : 37939.906 micros/op 26 ops/sec; 29.2 MB/s (1636 of 1999 found) With this change: seekrandom : 8527.720 micros/op 117 ops/sec; 129.7 MB/s (6530 of 7999 found) ``` ~4.5X perf improvement. Taken on an average of 3 runs. Closes meta#3884 Differential Revision: D8082143 Pulled By: sagar0 fbshipit-source-id: 4d7a8561cbac03478663713df4d31ad2620253bb
This PR extends the improvements in #3282 to also work when using Direct IO.
We see 4.5X performance improvement in seekrandom benchmark doing long range scans, when using direct reads, on flash.
Description:
This change improves the performance of iterators doing long range scans (e.g. big/full index or table scans in MyRocks) by using readahead and prefetching additional data on each disk IO, and storing in a local buffer. This prefetching is automatically enabled on noticing more than 2 IOs for the same table file during iteration. The readahead size starts with 8KB and is exponentially increased on each additional sequential IO, up to a max of 256 KB. This helps in cutting down the number of IOs needed to complete the range scan.
Implementation Details:
FilePrefetchBufferas the underlying buffer to store the readahead data.FilePrefetchBuffercan now take file_reader, readahead_size and max_readahead_size as input to the constructor, and automatically do readahead.FilePrefetchBuffer::TryReadFromCachecan now callFilePrefetchBuffer::Prefetchif readahead is enabled.AlignedBuffer(which is the underlying store forFilePrefetchBuffer) now takes a few additional args inAlignedBuffer::AllocateNewBufferto allow copying data from the old buffer.AlignedBuffer::cursize_was not being properly kept up-to-date.Constraints:
use_direct_io_for_flush_and_compactionandcompaction_readahead_size, and the current feature takes precautions not to mess with them.Benchmarks:
I used the same benchmark as used in #3282.
Data fill:
Do a long range scan: Seekrandom with large number of nexts
~4.5X perf improvement. Taken on an average of 3 runs.