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

[httpcomponents-client] branch HTTPCLIENT-2037 created (now 667fc9e)

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

michaelo pushed a change to branch HTTPCLIENT-2037
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.


      at 667fc9e  HTTPCLIENT-2037: AIMDBackoffManager should use TimeValue

This branch includes the following new commits:

     new 667fc9e  HTTPCLIENT-2037: AIMDBackoffManager should use TimeValue

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.



[httpcomponents-client] 01/01: HTTPCLIENT-2037: AIMDBackoffManager should use TimeValue

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

michaelo pushed a commit to branch HTTPCLIENT-2037
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 667fc9e218e9cb703c6ec61cffd21901dfe52ce4
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Dec 15 12:21:59 2019 +0100

    HTTPCLIENT-2037: AIMDBackoffManager should use TimeValue
---
 .../http/impl/classic/AIMDBackoffManager.java      | 23 +++++++++++-----------
 .../http/impl/classic/TestAIMDBackoffManager.java  |  3 ++-
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java
index 5341826..5220198 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/AIMDBackoffManager.java
@@ -34,6 +34,7 @@ import org.apache.hc.client5.http.classic.BackoffManager;
 import org.apache.hc.core5.annotation.Experimental;
 import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * <p>The {@code AIMDBackoffManager} applies an additive increase,
@@ -62,7 +63,7 @@ public class AIMDBackoffManager implements BackoffManager {
     private final Clock clock;
     private final Map<HttpRoute, Long> lastRouteProbes;
     private final Map<HttpRoute, Long> lastRouteBackoffs;
-    private long coolDown = 5 * 1000L;
+    private TimeValue coolDown = TimeValue.ofSeconds(5L);
     private double backoffFactor = 0.5;
     private int cap = 2; // Per RFC 2616 sec 8.1.4
 
@@ -90,7 +91,7 @@ public class AIMDBackoffManager implements BackoffManager {
             final int curr = connPerRoute.getMaxPerRoute(route);
             final Long lastUpdate = getLastUpdate(lastRouteBackoffs, route);
             final long now = clock.getCurrentTime();
-            if (now - lastUpdate.longValue() < coolDown) {
+            if (now - lastUpdate.longValue() < coolDown.toMillis()) {
                 return;
             }
             connPerRoute.setMaxPerRoute(route, getBackedOffPoolSize(curr));
@@ -113,7 +114,8 @@ public class AIMDBackoffManager implements BackoffManager {
             final Long lastProbe = getLastUpdate(lastRouteProbes, route);
             final Long lastBackoff = getLastUpdate(lastRouteBackoffs, route);
             final long now = clock.getCurrentTime();
-            if (now - lastProbe.longValue() < coolDown || now - lastBackoff.longValue() < coolDown) {
+            if (now - lastProbe.longValue() < coolDown.toMillis()
+                || now - lastBackoff.longValue() < coolDown.toMillis()) {
                 return;
             }
             connPerRoute.setMaxPerRoute(route, max);
@@ -144,15 +146,14 @@ public class AIMDBackoffManager implements BackoffManager {
     }
 
     /**
-     * Sets the amount of time, in milliseconds, to wait between
-     * adjustments in pool sizes for a given host, to allow
-     * enough time for the adjustments to take effect. Defaults
-     * to 5000L (5 seconds).
-     * @param l must be positive
+     * Sets the amount of time to wait between adjustments in
+     * pool sizes for a given host, to allow enough time for
+     * the adjustments to take effect. Defaults to 5 seconds.
+     * @param coolDown must be positive
      */
-    public void setCooldownMillis(final long l) {
-        Args.positive(coolDown, "Cool down");
-        coolDown = l;
+    public void setCoolDown(final TimeValue coolDown) {
+        Args.positive(coolDown.getDuration(), "coolDown");
+        this.coolDown = coolDown;
     }
 
     /**
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAIMDBackoffManager.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAIMDBackoffManager.java
index cb00a97..e1acb18 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAIMDBackoffManager.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAIMDBackoffManager.java
@@ -34,6 +34,7 @@ import java.util.Random;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.classic.BackoffManager;
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.util.TimeValue;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -166,7 +167,7 @@ public class TestAIMDBackoffManager {
             cd++;
         }
         final long now = System.currentTimeMillis();
-        impl.setCooldownMillis(cd);
+        impl.setCoolDown(TimeValue.ofMilliseconds(cd));
         clock.setCurrentTime(now);
         impl.probe(route);
         final int max0 = connPerRoute.getMaxPerRoute(route);