From e9a4b307aff6cbc43428854c0316ba83c1ad21f6 Mon Sep 17 00:00:00 2001 From: Yingxin Date: Fri, 12 Apr 2019 03:51:49 +0800 Subject: [PATCH] posix_data_source_impl: adaptive prefetch size Signed-off-by: Yingxin --- include/seastar/net/posix-stack.hh | 4 +++- src/net/posix-stack.cc | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/seastar/net/posix-stack.hh b/include/seastar/net/posix-stack.hh index 186efc6e517..7c23a82eb13 100644 --- a/include/seastar/net/posix-stack.hh +++ b/include/seastar/net/posix-stack.hh @@ -105,8 +105,10 @@ class posix_data_source_impl final : public data_source_impl { lw_shared_ptr _fd; temporary_buffer _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 fd, size_t buf_size = 8192) + explicit posix_data_source_impl(lw_shared_ptr fd, size_t buf_size = 1 << 13) : _fd(std::move(fd)), _buf(buf_size), _buf_size(buf_size) {} future> get() override; future<> close() override; diff --git a/src/net/posix-stack.cc b/src/net/posix-stack.cc index 5a8657afa34..530c754a726 100644 --- a/src/net/posix-stack.cc +++ b/src/net/posix-stack.cc @@ -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(_buf_size); return make_ready_future>(std::move(ret)); });