Skip to content

Commit

Permalink
posix_data_source_impl: adaptive prefetch size
Browse files Browse the repository at this point in the history
Signed-off-by: Yingxin <[email protected]>
  • Loading branch information
cyx1231st committed Apr 30, 2019
1 parent 23c9610 commit e9a4b30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/seastar/net/posix-stack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ class posix_data_source_impl final : public data_source_impl {
lw_shared_ptr<pollable_fd> _fd;
temporary_buffer<char> _buf;
size_t _buf_size;
static constexpr size_t min_buf_size = 1 << 9;
static constexpr size_t max_buf_size = 1 << 19;
public:
explicit posix_data_source_impl(lw_shared_ptr<pollable_fd> fd, size_t buf_size = 8192)
explicit posix_data_source_impl(lw_shared_ptr<pollable_fd> fd, size_t buf_size = 1 << 13)
: _fd(std::move(fd)), _buf(buf_size), _buf_size(buf_size) {}
future<temporary_buffer<char>> get() override;
future<> close() override;
Expand Down
5 changes: 5 additions & 0 deletions src/net/posix-stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ posix_data_source_impl::get() {
return _fd->read_some(_buf.get_write(), _buf_size).then([this] (size_t size) {
_buf.trim(size);
auto ret = std::move(_buf);
if (_buf_size == size) {
_buf_size = std::min(max_buf_size, _buf_size << 2);
} else if (size < (_buf_size >> 2)) {
_buf_size = std::max(min_buf_size, _buf_size >> 2);
}
_buf = temporary_buffer<char>(_buf_size);
return make_ready_future<temporary_buffer<char>>(std::move(ret));
});
Expand Down

0 comments on commit e9a4b30

Please sign in to comment.