You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2022/10/19 11:55:35 UTC

[httpcomponents-core] branch master updated (fa9f5f8d0 -> f1bb865b6)

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

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


    omit fa9f5f8d0 HTTPCORE-726: Improved capacity management in SharedInputBuffer
    omit 869b115ab Fixed integration tests broken by JUnit 5 upgrade
     new f1bb865b6 HTTPCORE-726: Improved capacity management in SharedInputBuffer

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (fa9f5f8d0)
            \
             N -- N -- N   refs/heads/master (f1bb865b6)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 ...gResponseOutOfOrderStrategyIntegrationTest.java |  3 +-
 .../hc/core5/testing/nio/H2IntegrationTest.java    | 39 +++++++-------
 .../nio/H2ServerAndMultiplexingRequesterTest.java  |  2 -
 .../testing/nio/H2SocksProxyIntegrationTest.java   | 55 +++++++++++---------
 .../hc/core5/testing/nio/Http1IntegrationTest.java | 39 +++++++-------
 ...se.java => Http1SocksProxyIntegrationTest.java} | 59 +++++++++-------------
 .../testing/nio/InternalH2ServerTestBase.java      | 19 +++----
 pom.xml                                            | 11 ----
 8 files changed, 100 insertions(+), 127 deletions(-)
 copy httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultAddressResolver.java => httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2SocksProxyIntegrationTest.java (56%)
 copy httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/{InternalH2ServerTestBase.java => Http1SocksProxyIntegrationTest.java} (59%)


[httpcomponents-core] 01/01: HTTPCORE-726: Improved capacity management in SharedInputBuffer

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

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

commit f1bb865b6f4959a56d89f6eb7a13cee5ac909fb6
Author: John Leacox <jo...@gmail.com>
AuthorDate: Mon Oct 17 17:29:06 2022 +0200

    HTTPCORE-726: Improved capacity management in SharedInputBuffer
---
 .../nio/support/classic/SharedInputBuffer.java     | 37 ++++++++++++++--------
 .../nio/support/classic/TestSharedInputBuffer.java |  2 +-
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedInputBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedInputBuffer.java
index b19367540..45dea032c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedInputBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedInputBuffer.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http.nio.support.classic;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.nio.ByteBuffer;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.hc.core5.annotation.Contract;
@@ -41,14 +42,19 @@ import org.apache.hc.core5.http.nio.CapacityChannel;
 @Contract(threading = ThreadingBehavior.SAFE)
 public final class SharedInputBuffer extends AbstractSharedBuffer implements ContentInputBuffer {
 
+    private final int initialBufferSize;
+    private final AtomicInteger capacityIncrement;
+
     private volatile CapacityChannel capacityChannel;
 
     public SharedInputBuffer(final ReentrantLock lock, final int initialBufferSize) {
         super(lock, initialBufferSize);
+        this.initialBufferSize = initialBufferSize;
+        this.capacityIncrement = new AtomicInteger(0);
     }
 
     public SharedInputBuffer(final int bufferSize) {
-        super(new ReentrantLock(), bufferSize);
+        this(new ReentrantLock(), bufferSize);
     }
 
     public int fill(final ByteBuffer src) {
@@ -65,13 +71,22 @@ public final class SharedInputBuffer extends AbstractSharedBuffer implements Con
         }
     }
 
+    private void incrementCapacity() throws IOException {
+        if (capacityChannel != null) {
+            final int increment = capacityIncrement.getAndSet(0);
+            if (increment > 0) {
+                capacityChannel.update(increment);
+            }
+        }
+    }
+
     public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
         lock.lock();
         try {
             this.capacityChannel = capacityChannel;
             setInputMode();
-            if (buffer().hasRemaining()) {
-                capacityChannel.update(buffer().remaining());
+            if (buffer().position() == 0) {
+                capacityChannel.update(initialBufferSize);
             }
         } finally {
             lock.unlock();
@@ -106,11 +121,9 @@ public final class SharedInputBuffer extends AbstractSharedBuffer implements Con
                 return -1;
             }
             final int b = buffer().get() & 0xff;
-            if (!buffer().hasRemaining() && capacityChannel != null) {
-                setInputMode();
-                if (buffer().hasRemaining()) {
-                    capacityChannel.update(buffer().remaining());
-                }
+            capacityIncrement.incrementAndGet();
+            if (!buffer().hasRemaining()) {
+                incrementCapacity();
             }
             return b;
         } finally {
@@ -132,11 +145,9 @@ public final class SharedInputBuffer extends AbstractSharedBuffer implements Con
             }
             final int chunk = Math.min(buffer().remaining(), len);
             buffer().get(b, off, chunk);
-            if (!buffer().hasRemaining() && capacityChannel != null) {
-                setInputMode();
-                if (buffer().hasRemaining()) {
-                    capacityChannel.update(buffer().remaining());
-                }
+            capacityIncrement.addAndGet(chunk);
+            if (!buffer().hasRemaining()) {
+                incrementCapacity();
             }
             return chunk;
         } finally {
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java
index ac1d101cb..2bb8f81a1 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java
@@ -132,7 +132,7 @@ public class TestSharedInputBuffer {
 
         Assertions.assertEquals(Boolean.TRUE, task1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()));
         Assertions.assertEquals(Integer.valueOf('a'), task2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()));
-        Mockito.verify(capacityChannel).update(10);
+        Mockito.verify(capacityChannel).update(1);
     }
 
     @Test