Skip to content

Commit

Permalink
📝 add reserve buf for wirter
Browse files Browse the repository at this point in the history
  • Loading branch information
Xudong-Huang committed Apr 30, 2024
1 parent 64dc965 commit 6488977
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/conetty/queued_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ impl<W: Write> BufWriter<W> {
buf: BytesMut::with_capacity(1024 * 32),
}
}
#[inline]
fn reserve_buf(&mut self) {
let remain = self.buf.capacity() - self.buf.len();
if remain < 1024 {
self.buf.reserve(1024 * 32 - remain);
}
}

#[inline]
fn put_data(&mut self, data: &[u8]) {
Expand Down Expand Up @@ -59,6 +66,7 @@ impl<W: Write> QueuedWriter<W> {
// and the next writer would try to acquire the lock
// this only relax the write lock contention
let mut writer = self.writer.lock().unwrap();
writer.reserve_buf();

loop {
let mut cnt = 0;
Expand Down

0 comments on commit 6488977

Please sign in to comment.