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:42:26 UTC
[tomcat] 02/02: Reduce the memory footprint of closed HTTP/2 streams
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit e57d32d8636811ad26128dab53ca06c71437aa5e
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 878fd2f..1ddf994 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -77,13 +77,15 @@ 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);
@@ -733,11 +735,16 @@ 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 52b1a30..dca98a2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -104,6 +104,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