Skip to content

Commit e9a4b30

Browse files
committed
posix_data_source_impl: adaptive prefetch size
Signed-off-by: Yingxin <[email protected]>
1 parent 23c9610 commit e9a4b30

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/seastar/net/posix-stack.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ class posix_data_source_impl final : public data_source_impl {
105105
lw_shared_ptr<pollable_fd> _fd;
106106
temporary_buffer<char> _buf;
107107
size_t _buf_size;
108+
static constexpr size_t min_buf_size = 1 << 9;
109+
static constexpr size_t max_buf_size = 1 << 19;
108110
public:
109-
explicit posix_data_source_impl(lw_shared_ptr<pollable_fd> fd, size_t buf_size = 8192)
111+
explicit posix_data_source_impl(lw_shared_ptr<pollable_fd> fd, size_t buf_size = 1 << 13)
110112
: _fd(std::move(fd)), _buf(buf_size), _buf_size(buf_size) {}
111113
future<temporary_buffer<char>> get() override;
112114
future<> close() override;

src/net/posix-stack.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ posix_data_source_impl::get() {
316316
return _fd->read_some(_buf.get_write(), _buf_size).then([this] (size_t size) {
317317
_buf.trim(size);
318318
auto ret = std::move(_buf);
319+
if (_buf_size == size) {
320+
_buf_size = std::min(max_buf_size, _buf_size << 2);
321+
} else if (size < (_buf_size >> 2)) {
322+
_buf_size = std::max(min_buf_size, _buf_size >> 2);
323+
}
319324
_buf = temporary_buffer<char>(_buf_size);
320325
return make_ready_future<temporary_buffer<char>>(std::move(ret));
321326
});

0 commit comments

Comments
 (0)