hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-core git commit: HTTPCORE-485: Remove one buffer from SSLIOSession.java because it is not used.
Date Sat, 26 Aug 2017 09:30:42 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/master c3472dfb1 -> 09ca1b5f4


HTTPCORE-485: Remove one buffer from SSLIOSession.java because it is not used.

Currently for each remote connection we make an SSLIOSession.
Each SSLIOSession has 4 buffers:
private final SSLBuffer inEncrypted;
private final SSLBuffer outEncrypted;
private final SSLBuffer inPlain;
private final SSLBuffer outPlain;
And each of these buffers occupies 16K (64K per remote connection).
If an application uses NIO for long polling and there are (for example) 9000 idle long polling
connections waiting for notifications.
This makes 9000 * 64K = 576 000K (576MB).
As outPlain buffer is not used if we remove it this will save 25% of the memory from the buffers
used for the remote connections. In the example case this is 144MB.


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/09ca1b5f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/09ca1b5f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/09ca1b5f

Branch: refs/heads/master
Commit: 09ca1b5f49cacc36d9309b1bfa5d3489f68939b8
Parents: c3472df
Author: Todor Bonchev <31352118+TodorBonchev@users.noreply.github.com>
Authored: Fri Aug 25 18:49:12 2017 +0300
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Fri Aug 25 19:15:18 2017 +0200

----------------------------------------------------------------------
 .../hc/core5/reactor/ssl/SSLIOSession.java      | 54 +++-----------------
 1 file changed, 7 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/09ca1b5f/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index 64bf23d..83bd982 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -74,7 +74,6 @@ public class SSLIOSession implements IOSession {
     private final SSLBuffer inEncrypted;
     private final SSLBuffer outEncrypted;
     private final SSLBuffer inPlain;
-    private final SSLBuffer outPlain;
     private final ByteChannel channel;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
@@ -159,7 +158,6 @@ public class SSLIOSession implements IOSession {
         // Allocate buffers for application (unencrypted) data
         final int appBufferSize = sslSession.getApplicationBufferSize();
         this.inPlain = SSLBufferManagement.create(sslBufferManagement, appBufferSize);
-        this.outPlain = SSLBufferManagement.create(sslBufferManagement, appBufferSize);
         this.channel = new ByteChannel() {
 
             @Override
@@ -228,8 +226,6 @@ public class SSLIOSession implements IOSession {
         this.inEncrypted.release();
         this.outEncrypted.release();
         this.inPlain.release();
-        this.outPlain.release();
-
         doHandshake();
     }
 
@@ -287,18 +283,10 @@ public class SSLIOSession implements IOSession {
                 // Generate outgoing handshake data
 
                 // Acquire buffers
-                final ByteBuffer outPlainBuf = this.outPlain.acquire();
                 final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
 
-                // Perform operations
-                outPlainBuf.flip();
-                result = doWrap(outPlainBuf, outEncryptedBuf);
-                outPlainBuf.compact();
-
-                // Release outPlain if empty
-                if (outPlainBuf.position() == 0) {
-                    this.outPlain.release();
-                }
+                // Just wrap an empty buffer because there is no data to write.
+                result = doWrap(EMPTY_BUFFER, outEncryptedBuf);
 
                 if (result.getStatus() != Status.OK) {
                     handshaking = false;
@@ -570,30 +558,12 @@ public class SSLIOSession implements IOSession {
         if (this.status != ACTIVE) {
             throw new ClosedChannelException();
         }
-        if (this.outPlain.hasData()) {
-            // Acquire buffers
-            final ByteBuffer outPlainBuf = this.outPlain.acquire();
-            final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
-
-            // Perform operations
-            outPlainBuf.flip();
-            doWrap(outPlainBuf, outEncryptedBuf);
-            outPlainBuf.compact();
-
-            // Release outPlain if empty
-            if (outPlainBuf.position() == 0) {
-                this.outPlain.release();
-            }
-        }
-        if (!this.outPlain.hasData()) {
-            final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
-            final SSLEngineResult result = doWrap(src, outEncryptedBuf);
-            if (result.getStatus() == Status.CLOSED) {
-                this.status = CLOSED;
-            }
-            return result.bytesConsumed();
+        final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
+        final SSLEngineResult result = doWrap(src, outEncryptedBuf);
+        if (result.getStatus() == Status.CLOSED) {
+            this.status = CLOSED;
         }
-        return 0;
+        return result.bytesConsumed();
     }
 
     private synchronized int readPlain(final ByteBuffer dst) {
@@ -629,13 +599,6 @@ public class SSLIOSession implements IOSession {
         return this.inPlain.hasData();
     }
 
-    /**
-     * @since 5.0
-     */
-    public synchronized boolean hasOutputDate() {
-        return this.outPlain.hasData();
-    }
-
     @Override
     public synchronized void close() {
         if (this.status >= CLOSING) {
@@ -660,7 +623,6 @@ public class SSLIOSession implements IOSession {
         this.inEncrypted.release();
         this.outEncrypted.release();
         this.inPlain.release();
-        this.outPlain.release();
 
         this.status = CLOSED;
         this.session.shutdown(shutdownType);
@@ -795,8 +757,6 @@ public class SSLIOSession implements IOSession {
         buffer.append(!this.inPlain.hasData() ? 0 : inPlain.acquire().position());
         buffer.append("][");
         buffer.append(!this.outEncrypted.hasData() ? 0 : outEncrypted.acquire().position());
-        buffer.append("][");
-        buffer.append(!this.outPlain.hasData() ? 0 : outPlain.acquire().position());
         buffer.append("]");
         return buffer.toString();
     }


Mime
View raw message