You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2019/12/29 16:59:43 UTC

[httpcomponents-core] branch master updated (b74b909 -> d05d79e)

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

rschmitt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git.


    from b74b909  Simplified resource deallocation by reactive data consumer
     new 1d49b38  ReactiveTestUtils: Fix reproducibility
     new d05d79e  Clean up connection window management

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:
 .../impl/nio/AbstractH2StreamMultiplexer.java      | 38 +++++++++-------------
 .../core5/testing/reactive/ReactiveTestUtils.java  |  2 +-
 2 files changed, 17 insertions(+), 23 deletions(-)


[httpcomponents-core] 01/02: ReactiveTestUtils: Fix reproducibility

Posted by rs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 1d49b3886b25d4e98f18bf3f5fd51892c049ab9f
Author: Ryan Schmitt <rs...@pobox.com>
AuthorDate: Sat Dec 28 20:19:21 2019 -0500

    ReactiveTestUtils: Fix reproducibility
---
 .../java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java
index 3b67f52..6a6bed3 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/reactive/ReactiveTestUtils.java
@@ -102,7 +102,7 @@ public class ReactiveTestUtils {
                     final int bufferLength = (int) Math.min(remainingLength, 1 + random.nextInt(maximumBlockSize));
                     final byte[] bs = new byte[bufferLength];
                     for (int i = 0; i < bufferLength; i++) {
-                        final byte b = RANGE[(int) (Math.random() * RANGE.length)];
+                        final byte b = RANGE[(int) (random.nextDouble() * RANGE.length)];
                         bs[i] = b;
                     }
                     if (hash != null) {


[httpcomponents-core] 02/02: Clean up connection window management

Posted by rs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit d05d79e37e2225f94aa683ddf73a523b012dd64c
Author: Ryan Schmitt <rs...@pobox.com>
AuthorDate: Sat Dec 28 17:45:37 2019 -0500

    Clean up connection window management
    
    This commit implements the following changes to input window management:
    
    1. The `lowMark` is set according to local settings, not remote settings
    2. The connection window is set to `Integer.MAX_VALUE` during `SETTINGS` exchange
    3. The connection window low mark is now a constant value (10 MiB)
    4. The input window update code in `onOutput` has been removed
---
 .../impl/nio/AbstractH2StreamMultiplexer.java      | 38 +++++++++-------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
index 91280c3..7b02c82 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
@@ -26,6 +26,7 @@
  */
 package org.apache.hc.core5.http2.impl.nio;
 
+import javax.net.ssl.SSLSession;
 import java.io.IOException;
 import java.net.SocketAddress;
 import java.nio.ByteBuffer;
@@ -42,8 +43,6 @@ import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import javax.net.ssl.SSLSession;
-
 import org.apache.hc.core5.concurrent.Cancellable;
 import org.apache.hc.core5.concurrent.CancellableDependency;
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -94,6 +93,7 @@ import org.apache.hc.core5.util.Timeout;
 abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnection {
 
     private static final long LINGER_TIME = 1000; // 1 second
+    private static final long CONNECTION_WINDOW_LOW_MARK = 10 * 1024 * 1024; // 10 MiB
 
     enum ConnectionHandshake { READY, ACTIVE, GRACEFUL_SHUTDOWN, SHUTDOWN}
     enum SettingsHandshake { READY, TRANSMITTED, ACKED }
@@ -125,11 +125,10 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
 
     private int initInputWinSize;
     private int initOutputWinSize;
+    private int lowMark;
 
     private volatile H2Config remoteConfig;
 
-    private int lowMark;
-
     private Continuation continuation;
 
     private int processedRemoteStreamId;
@@ -419,6 +418,7 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
 
         commitFrame(settingsFrame);
         localSettingState = SettingsHandshake.TRANSMITTED;
+        maximizeConnWindow(connInputWindow.get());
 
         if (streamListener != null) {
             final int initInputWindow = connInputWindow.get();
@@ -466,16 +466,6 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
             ioSession.getLock().unlock();
         }
 
-        final int connWinSize = connInputWindow.get();
-        if (connWinSize < lowMark) {
-            final int delta = initInputWinSize - connWinSize;
-            if (delta > 0) {
-                final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(0, delta);
-                commitFrame(windowUpdateFrame);
-                updateInputWindow(0, connInputWindow, delta);
-            }
-        }
-
         if (connState.compareTo(ConnectionHandshake.SHUTDOWN) < 0) {
 
             if (connOutputWindow.get() > 0 && remoteSettingState == SettingsHandshake.ACKED) {
@@ -1000,13 +990,8 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
                 stream.produceInputCapacityUpdate();
             }
             final int connWinSize = updateInputWindow(0, connInputWindow, -frameLength);
-            if (connWinSize < lowMark) {
-                final int chunk = Integer.MAX_VALUE - connWinSize;
-                if (chunk > 0) {
-                    final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(0, chunk);
-                    commitFrame(windowUpdateFrame);
-                    updateInputWindow(0, connInputWindow, chunk);
-                }
+            if (connWinSize < CONNECTION_WINDOW_LOW_MARK) {
+                maximizeConnWindow(connWinSize);
             }
         }
         if (stream.isRemoteClosed()) {
@@ -1021,6 +1006,15 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
         stream.consumeData(payload);
     }
 
+    private void maximizeConnWindow(final int connWinSize) throws IOException {
+        final int delta = Integer.MAX_VALUE - connWinSize;
+        if (delta > 0) {
+            final RawFrame windowUpdateFrame = frameFactory.createWindowUpdate(0, delta);
+            commitFrame(windowUpdateFrame);
+            updateInputWindow(0, connInputWindow, delta);
+        }
+    }
+
     private void consumePushPromiseFrame(final RawFrame frame, final ByteBuffer payload, final H2Stream promisedStream) throws HttpException, IOException {
         final int promisedStreamId = promisedStream.getId();
         if (!frame.isFlagSet(FrameFlag.END_HEADERS)) {
@@ -1203,7 +1197,6 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
                 }
             }
         }
-        lowMark = initOutputWinSize / 2;
     }
 
     private void applyLocalSettings() throws H2ConnectionException {
@@ -1223,6 +1216,7 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
                 }
             }
         }
+        lowMark = initInputWinSize / 2;
     }
 
     @Override