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

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 112992d9e16c76bd3546499477f29ef864bf25ac
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 25 14:40:27 2020 +0100

    Reduce the memory footprint of closed HTTP/2 streams
---
 java/org/apache/coyote/http2/Stream.java | 27 +++++++++++++++++----------
 webapps/docs/changelog.xml               |  3 +++
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/coyote/http2/Stream.java 
b/java/org/apache/coyote/http2/Stream.java
index 5f28617..bf13b11 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -74,13 +74,15 @@ public class Stream extends AbstractStream implements 
HeaderEmitter {
     // State machine would be too much overhead
     private int headerState = HEADER_STATE_START;
     private StreamException headerException = null;
-    // TODO: null these when finished to reduce memory used by closed stream
-    private final Request coyoteRequest;
-    private StringBuilder cookieHeader = null;
-    private final Response coyoteResponse = new Response();
-    private final StreamInputBuffer inputBuffer;
-    private final StreamOutputBuffer streamOutputBuffer = new 
StreamOutputBuffer();
-    private final Http2OutputBuffer http2OutputBuffer =
+
+    // These will be set to null once the Stream closes to reduce the memory
+    // footprint.
+    private volatile Request coyoteRequest;
+    private volatile StringBuilder cookieHeader = null;
+    private volatile Response coyoteResponse = new Response();
+    private volatile StreamInputBuffer inputBuffer;
+    private volatile StreamOutputBuffer streamOutputBuffer = new 
StreamOutputBuffer();
+    private volatile Http2OutputBuffer http2OutputBuffer =
             new Http2OutputBuffer(coyoteResponse, streamOutputBuffer);
 
 
@@ -689,11 +691,16 @@ public class Stream extends AbstractStream implements 
HeaderEmitter {
      * This method is called recycle for consistency with the rest of the 
Tomcat
      * code base. Currently, it only sets references to null for the purposes 
of
      * reducing memory footprint. It does not fully recycle the Stream ready 
for
-     * re-use since Stream objects are not re-used.
+     * re-use since Stream objects are not re-used. This is useful because
+     * Stream instances are retained for a period after the Stream closes.
      */
     final void recycle() {
-        // Currently a NO-OP. This will change shortly to address the TODO for
-        // nulling out references.
+        coyoteRequest = null;
+        cookieHeader = null;
+        coyoteResponse = null;
+        inputBuffer = null;
+        streamOutputBuffer = null;
+        http2OutputBuffer = null;
     }
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 3a1dd94..15f36ae 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -100,6 +100,9 @@
         Once an HTTP/2 stream has been closed, ensure that the code that cleans
         up references that are no longer required is called. (markt)
       </fix>
+      <fix>
+        Reduce the memory footprint of closed HTTP/2 streams. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Other">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to