MCPcopy Create free account
hub / github.com/apache/arrow / CoalescedRead

Function CoalescedRead

cpp/src/arrow/filesystem/s3fs_benchmark.cc:255–292  ·  view source on GitHub ↗

Read the file in small chunks, but using read coalescing.

Source from the content-addressed store, hash-verified

253
254/// Read the file in small chunks, but using read coalescing.
255static void CoalescedRead(benchmark::State& st, S3FileSystem* fs,
256 const std::string& path) {
257 int64_t total_bytes = 0;
258 int total_items = 0;
259 for (auto _ : st) {
260 std::shared_ptr<io::RandomAccessFile> file;
261 std::shared_ptr<Buffer> buf;
262 int64_t size = 0;
263 ASSERT_OK_AND_ASSIGN(file, fs->OpenInputFile(path));
264 ASSERT_OK_AND_ASSIGN(size, file->GetSize());
265 total_items += 1;
266
267 io::internal::ReadRangeCache cache(
268 file, {},
269 io::CacheOptions{/*hole_size_limit=*/8192, /*range_size_limit=*/64 * 1024 * 1024,
270 /*lazy=*/false});
271 std::vector<io::ReadRange> ranges;
272
273 int64_t offset = 0;
274 while (offset < size) {
275 const int64_t read = std::min(size, kChunkSize);
276 ranges.push_back(io::ReadRange{offset, read});
277 offset += read;
278 }
279 ASSERT_OK(cache.Cache(ranges));
280
281 offset = 0;
282 while (offset < size) {
283 const int64_t read = std::min(size, kChunkSize);
284 ASSERT_OK_AND_ASSIGN(buf, cache.Read({offset, read}));
285 total_bytes += buf->size();
286 offset += read;
287 }
288 }
289 st.SetBytesProcessed(total_bytes);
290 st.SetItemsProcessed(total_items);
291 std::cerr << "Read the file " << total_items << " times" << std::endl;
292}
293
294/// Read a Parquet file from S3.
295static void ParquetRead(benchmark::State& st, S3FileSystem* fs, const std::string& path,

Calls 7

push_backMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
OpenInputFileMethod · 0.45
GetSizeMethod · 0.45
CacheMethod · 0.45
ReadMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected