Skip to content

Commit db7f602

Browse files
drymancopybara-github
authored andcommitted
Set readahead_buffer_size default to 0 for ArrayRecordReader.
Read-ahead is only useful when performing sequential read, which is much slower than the parallel-read feature. The read-ahead buffer occupies extra memory space with little benefit to both random access and batch access, hence disables it by default. PiperOrigin-RevId: 842735797
1 parent a723291 commit db7f602

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

cpp/array_record_reader.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ ArrayRecordReaderBase::Options::FromString(absl::string_view text) {
167167
// ReadaheadBuffer
168168
options_parser.AddOption(
169169
"readahead_buffer_size",
170-
ValueParser::Or(
171-
ValueParser::Enum({{"auto", kDefaultReadaheadBufferSize}},
172-
&options.readahead_buffer_size_),
173-
ValueParser::Bytes(0, std::numeric_limits<uint64_t>::max(),
174-
&options.readahead_buffer_size_)));
170+
ValueParser::Or(ValueParser::Enum({{"auto", kDefaultReadaheadBufferSize}},
171+
&options.readahead_buffer_size_),
172+
ValueParser::Bytes(/*min_value=*/0,
173+
/*max_value=*/1024 * 1024 * 1024,
174+
&options.readahead_buffer_size_)));
175175
// Index storage option
176176
options_parser.AddOption(
177177
"index_storage_option",

cpp/array_record_reader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class ArrayRecordReaderBase : public riegeli::Object {
8181
// "max_parallelism" ":" max_parallelism
8282
// "index_storage_option" ":" index_storage_option
8383
// readahead_buffer_size ::= non-negative integer expressed as real with
84-
// optional suffix [BkKMGTPE]. (Default 16MB). Set to 0 optimizes random
85-
// access performance.
84+
// optional suffix [BKMG]. (Example 16MB). Set to 0 optimizes random
85+
// access performance. Defaults 0.
8686
// max_parallelism ::= `auto` or non-negative integer. Each parallel
8787
// thread owns its readhaed buffer with the size
8888
// `readahead_buffer_size`. (Default thread pool size) Set to 0
@@ -95,7 +95,7 @@ class ArrayRecordReaderBase : public riegeli::Object {
9595
// Readahead speeds up sequential reads, but harms random access. When using
9696
// ArrayRecord for random access, user should configure the buffer size with
9797
// 0.
98-
static constexpr uint64_t kDefaultReadaheadBufferSize = 1L << 24;
98+
static constexpr uint64_t kDefaultReadaheadBufferSize = 0;
9999
Options& set_readahead_buffer_size(uint64_t readahead_buffer_size) {
100100
readahead_buffer_size_ = readahead_buffer_size;
101101
return *this;

0 commit comments

Comments
 (0)