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:32:11 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/4.4.x 9caf4e637 -> 271c053d4


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/271c053d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/271c053d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/271c053d

Branch: refs/heads/4.4.x
Commit: 271c053d4b6e8b827e29715712d7faf0f975dcbf
Parents: 9caf4e6
Author: Todor Bonchev <31352118+TodorBonchev@users.noreply.github.com>
Authored: Fri Aug 25 19:14:45 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Fri Aug 25 19:16:23 2017 +0200

----------------------------------------------------------------------
 .../http/nio/reactor/ssl/SSLIOSession.java      | 66 +++++---------------
 1 file changed, 15 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/271c053d/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
index 847e26d..3aaede0 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
@@ -87,7 +87,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
     private final SSLBuffer inEncrypted;
     private final SSLBuffer outEncrypted;
     private final SSLBuffer inPlain;
-    private final SSLBuffer outPlain;
     private final InternalByteChannel channel;
     private final SSLSetupHandler handler;
 
@@ -164,7 +163,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
         // Allocate buffers for application (unencrypted) data
         final int appBuffersize = this.sslEngine.getSession().getApplicationBufferSize();
         this.inPlain = bufferManagementStrategy.constructBuffer(appBuffersize);
-        this.outPlain = bufferManagementStrategy.constructBuffer(appBuffersize);
     }
 
     /**
@@ -239,7 +237,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
         this.inEncrypted.release();
         this.outEncrypted.release();
         this.inPlain.release();
-        this.outPlain.release();
 
         doHandshake();
     }
@@ -295,28 +292,18 @@ public class SSLIOSession implements IOSession, SessionBufferStatus,
SocketAcces
         while (handshaking) {
             switch (this.sslEngine.getHandshakeStatus()) {
             case NEED_WRAP:
-                // Generate outgoing handshake data
+               // Generate outgoing handshake data
 
-                // Acquire buffers
-                ByteBuffer outPlainBuf = this.outPlain.acquire();
-                final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
+               // Acquire buffer
+               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();
-                    outPlainBuf = null;
-                }
+               // Just wrap an empty buffer because there is no data to write.
+               result = doWrap(ByteBuffer.allocate(0), outEncryptedBuf);
 
-
-                if (result.getStatus() != Status.OK) {
-                    handshaking = false;
-                }
-                break;
+               if (result.getStatus() != Status.OK) {
+                   handshaking = false;
+               }
+               break;
             case NEED_UNWRAP:
                 // Process incoming handshake data
 
@@ -573,31 +560,12 @@ public class SSLIOSession implements IOSession, SessionBufferStatus,
SocketAcces
         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();
-        } else {
-            return 0;
+        final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
+        final SSLEngineResult result = doWrap(src, outEncryptedBuf);
+        if (result.getStatus() == Status.CLOSED) {
+           this.status = CLOSED;
         }
+        return result.bytesConsumed();
     }
 
     private synchronized int readPlain(final ByteBuffer dst) {
@@ -656,7 +624,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
         this.inEncrypted.release();
         this.outEncrypted.release();
         this.inPlain.release();
-        this.outPlain.release();
 
     }
 
@@ -728,8 +695,7 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
     @Override
     public synchronized boolean hasBufferedOutput() {
         return (this.appBufferStatus != null && this.appBufferStatus.hasBufferedOutput())
-            || this.outEncrypted.hasData()
-            || this.outPlain.hasData();
+            || this.outEncrypted.hasData();
     }
 
     @Override
@@ -796,8 +762,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
         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