trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [trafficserver] 06/08: Avoid IOBufferReader::read_avail() call from MIOBuffer::high_water()
Date Tue, 10 Dec 2019 23:21:35 GMT
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 1861f369c6cdadc5a7afbce4671fb06bcbdfbc76
Author: Masaori Koshiba <masaori@apache.org>
AuthorDate: Fri Nov 1 11:31:01 2019 +0900

    Avoid IOBufferReader::read_avail() call from MIOBuffer::high_water()
    
    (cherry picked from commit 5e639715a52c6e0c09bdf8842989fbd83850c81a)
---
 iocore/eventsystem/IOBuffer.cc  | 20 ++++++++++++++++++++
 iocore/eventsystem/I_IOBuffer.h | 19 ++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/iocore/eventsystem/IOBuffer.cc b/iocore/eventsystem/IOBuffer.cc
index d2c130b..efa68e3 100644
--- a/iocore/eventsystem/IOBuffer.cc
+++ b/iocore/eventsystem/IOBuffer.cc
@@ -176,6 +176,26 @@ MIOBuffer::puts(char *s, int64_t len)
   return 0;
 }
 
+bool
+MIOBuffer::is_max_read_avail_more_than(int64_t size)
+{
+  bool no_reader = true;
+  for (auto &reader : this->readers) {
+    if (reader.allocated()) {
+      if (reader.is_read_avail_more_than(size)) {
+        return true;
+      }
+      no_reader = false;
+    }
+  }
+
+  if (no_reader && this->_writer) {
+    return (this->_writer->read_avail() > size);
+  }
+
+  return false;
+}
+
 //
 // IOBufferReader
 //
diff --git a/iocore/eventsystem/I_IOBuffer.h b/iocore/eventsystem/I_IOBuffer.h
index f83bc32..f8d317b 100644
--- a/iocore/eventsystem/I_IOBuffer.h
+++ b/iocore/eventsystem/I_IOBuffer.h
@@ -1094,7 +1094,7 @@ public:
   bool
   high_water()
   {
-    return max_read_avail() > water_mark;
+    return is_max_read_avail_more_than(this->water_mark);
   }
 
   /**
@@ -1176,8 +1176,25 @@ public:
   {
     return !_writer;
   }
+
+  /**
+    Get the maximum amount of available data across all of the readers.
+    If there're no allocated reader, return available data size of current writer.
+
+    This calls IOBufferReader::read_avail() and it could be expensive when it has a ton of
IOBufferBlock.
+    The `is_max_read_avail(int64_t size)` is preferred if possible.
+
+    @return maximum amount of available data
+   */
   int64_t max_read_avail();
 
+  /**
+    Check if there is more than @a size bytes available to read.
+
+    @return @c true if more than @a size byte are available.
+  */
+  bool is_max_read_avail_more_than(int64_t size);
+
   int max_block_count();
   void check_add_block();
 


Mime
View raw message