File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,18 @@ using namespace std;
12
12
namespace dfly {
13
13
14
14
io::Result<size_t > BufferedStreamerBase::WriteSome (const iovec* vec, uint32_t len) {
15
+ // Shrink producer_buf_ only if it is empty, its capacity reached 10 times more than max buffer
16
+ // memory and the write len is less than max buffer memory.
17
+ if (producer_buf_.InputLen () == 0 && producer_buf_.Capacity () > max_buffered_mem_ * 10 ) {
18
+ uint32_t write_len = 0 ;
19
+ for (uint32_t i = 0 ; i < len; ++i) {
20
+ write_len += vec->iov_len ;
21
+ }
22
+ if (write_len < max_buffered_mem_) {
23
+ producer_buf_ = base::IoBuf{max_buffered_mem_};
24
+ }
25
+ }
26
+
15
27
return io::BufSink{&producer_buf_}.WriteSome (vec, len);
16
28
}
17
29
@@ -57,7 +69,6 @@ error_code BufferedStreamerBase::ConsumeIntoSink(io::Sink* dest) {
57
69
return ec;
58
70
}
59
71
60
- // TODO: shrink big stash.
61
72
consumer_buf_.Clear ();
62
73
}
63
74
return std::error_code{};
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class BufferedStreamerBase : public io::Sink {
20
20
protected:
21
21
// Initialize with global cancellation and optional stall conditions.
22
22
BufferedStreamerBase (const Cancellation* cll, unsigned max_buffered_cnt = 5 ,
23
- unsigned max_buffered_mem = 512 )
23
+ unsigned max_buffered_mem = 8192 )
24
24
: cll_{cll}, max_buffered_cnt_{max_buffered_cnt}, max_buffered_mem_{max_buffered_mem} {
25
25
}
26
26
You can’t perform that action at this time.
0 commit comments