This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d14ad2b18 Use large IOBufferBlock only on sending DATA frame (#11229)
0d14ad2b18 is described below

commit 0d14ad2b18fde85eff69ba01a87d92940866c59f
Author: Masaori Koshiba <[email protected]>
AuthorDate: Tue May 14 09:57:39 2024 +0900

    Use large IOBufferBlock only on sending DATA frame (#11229)
---
 include/proxy/http2/HTTP2.h           |  1 +
 src/proxy/http2/HTTP2.cc              |  3 +++
 src/proxy/http2/Http2ClientSession.cc |  6 ++----
 src/proxy/http2/Http2Frame.cc         | 11 +++++++++--
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/proxy/http2/HTTP2.h b/include/proxy/http2/HTTP2.h
index 5d73022fec..5cabf2b2cd 100644
--- a/include/proxy/http2/HTTP2.h
+++ b/include/proxy/http2/HTTP2.h
@@ -434,6 +434,7 @@ public:
   static uint32_t stream_slow_log_threshold;
   static uint32_t header_table_size_limit;
   static uint32_t write_buffer_block_size;
+  static int64_t  write_buffer_block_size_index;
   static float    write_size_threshold;
   static uint32_t write_time_threshold;
   static uint32_t buffer_water_mark;
diff --git a/src/proxy/http2/HTTP2.cc b/src/proxy/http2/HTTP2.cc
index 8fcb9d93d6..3de6bbab04 100644
--- a/src/proxy/http2/HTTP2.cc
+++ b/src/proxy/http2/HTTP2.cc
@@ -496,6 +496,7 @@ uint32_t Http2::con_slow_log_threshold             = 0;
 uint32_t Http2::stream_slow_log_threshold          = 0;
 uint32_t Http2::header_table_size_limit            = 65536;
 uint32_t Http2::write_buffer_block_size            = 262144;
+int64_t  Http2::write_buffer_block_size_index      = BUFFER_SIZE_INDEX_256K;
 float    Http2::write_size_threshold               = 0.5;
 uint32_t Http2::write_time_threshold               = 100;
 uint32_t Http2::buffer_water_mark                  = 0;
@@ -556,6 +557,8 @@ Http2::init()
   REC_EstablishStaticConfigInt32U(write_time_threshold, 
"proxy.config.http2.write_time_threshold");
   REC_EstablishStaticConfigInt32U(buffer_water_mark, 
"proxy.config.http2.default_buffer_water_mark");
 
+  write_buffer_block_size_index = 
iobuffer_size_to_index(Http2::write_buffer_block_size, MAX_BUFFER_SIZE_INDEX);
+
   // If any settings is broken, ATS should not start
   
ink_release_assert(http2_settings_parameter_is_valid({HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
 max_concurrent_streams_in}));
   
ink_release_assert(http2_settings_parameter_is_valid({HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
 min_concurrent_streams_in}));
diff --git a/src/proxy/http2/Http2ClientSession.cc 
b/src/proxy/http2/Http2ClientSession.cc
index 61da1fc9f5..5cd713e527 100644
--- a/src/proxy/http2/Http2ClientSession.cc
+++ b/src/proxy/http2/Http2ClientSession.cc
@@ -114,9 +114,7 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, 
MIOBuffer *iobuf, IOB
   this->read_buffer->water_mark = 
connection_state.local_settings.get(HTTP2_SETTINGS_MAX_FRAME_SIZE);
   this->_read_buffer_reader     = reader ? reader : 
this->read_buffer->alloc_reader();
 
-  // This block size is the buffer size that we pass to SSLWriteBuffer
-  auto buffer_block_size_index = 
iobuffer_size_to_index(Http2::write_buffer_block_size, MAX_BUFFER_SIZE_INDEX);
-  this->write_buffer           = new_MIOBuffer(buffer_block_size_index);
+  this->write_buffer = new_MIOBuffer(HTTP2_HEADER_BUFFER_SIZE_INDEX);
 
   uint32_t buffer_water_mark;
   if (auto snis = this->_vc->get_service<TLSSNISupport>(); snis && 
snis->hints_from_sni.http2_buffer_water_mark.has_value()) {
@@ -127,7 +125,7 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, 
MIOBuffer *iobuf, IOB
   this->write_buffer->water_mark = buffer_water_mark;
 
   this->_write_buffer_reader  = this->write_buffer->alloc_reader();
-  this->_write_size_threshold = index_to_buffer_size(buffer_block_size_index) 
* Http2::write_size_threshold;
+  this->_write_size_threshold = 
index_to_buffer_size(Http2::write_buffer_block_size_index) * 
Http2::write_size_threshold;
 
   this->_handle_if_ssl(new_vc);
 
diff --git a/src/proxy/http2/Http2Frame.cc b/src/proxy/http2/Http2Frame.cc
index 52482ab68b..b477b48d6b 100644
--- a/src/proxy/http2/Http2Frame.cc
+++ b/src/proxy/http2/Http2Frame.cc
@@ -22,6 +22,7 @@
  */
 
 #include "proxy/http2/Http2Frame.h"
+#include "iocore/eventsystem/IOBuffer.h"
 
 //
 // Http2Frame
@@ -60,8 +61,14 @@ Http2DataFrame::write_to(MIOBuffer *iobuffer) const
     int64_t written = 0;
     // Fill current IOBufferBlock as much as possible to reduce SSL_write() 
calls
     while (written < this->_payload_len) {
-      int64_t read_len  = std::min(this->_payload_len - written, 
this->_reader->block_read_avail());
-      written          += iobuffer->write(this->_reader->start(), read_len);
+      int64_t read_len = std::min(this->_payload_len - written, 
this->_reader->block_read_avail());
+
+      if (iobuffer->block_write_avail() < read_len) {
+        // This block size is the buffer size that we pass to SSLWriteBuffer
+        iobuffer->append_block(Http2::write_buffer_block_size_index);
+      }
+
+      written += iobuffer->write(this->_reader->start(), read_len);
       this->_reader->consume(read_len);
     }
     len += written;

Reply via email to