You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/06/25 13:45:32 UTC

[tomcat] branch 8.5.x updated (abdd02d -> 112992d)

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

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


    from abdd02d  Make sure recycle() is called once the Stream is closed
     new d88e084  Add the plumbing to 'recycle' an HTTP/2 Stream
     new 112992d  Reduce the memory footprint of closed HTTP/2 streams

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/coyote/http2/Stream.java          | 34 ++++++++++++++++++-----
 java/org/apache/coyote/http2/StreamProcessor.java |  3 ++
 webapps/docs/changelog.xml                        |  3 ++
 3 files changed, 33 insertions(+), 7 deletions(-)


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


[tomcat] 02/02: Reduce the memory footprint of closed HTTP/2 streams

Posted by ma...@apache.org.
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/02: Add the plumbing to 'recycle' an HTTP/2 Stream

Posted by ma...@apache.org.
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 d88e0840c0278ed72fb14d9bf65b67097fe5a0bb
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 25 11:57:58 2020 +0100

    Add the plumbing to 'recycle' an HTTP/2 Stream
---
 java/org/apache/coyote/http2/Stream.java          | 13 +++++++++++++
 java/org/apache/coyote/http2/StreamProcessor.java |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java
index 32de3fe..5f28617 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -681,6 +681,19 @@ public class Stream extends AbstractStream implements HeaderEmitter {
         if (inputBuffer != null) {
             inputBuffer.receiveReset();
         }
+        recycle();
+    }
+
+
+    /*
+     * 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.
+     */
+    final void recycle() {
+        // Currently a NO-OP. This will change shortly to address the TODO for
+        // nulling out references.
     }
 
 
diff --git a/java/org/apache/coyote/http2/StreamProcessor.java b/java/org/apache/coyote/http2/StreamProcessor.java
index 0106cf4..5a24f44 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -86,6 +86,9 @@ class StreamProcessor extends AbstractProcessor {
                                         stream.getIdAsInt());
                             }
                             stream.close(se);
+                        } else {
+                            // stream.close() will call recycle so only need it here
+                            stream.recycle();
                         }
                     }
                 } catch (Exception e) {


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