[ 
https://issues.apache.org/jira/browse/HTTPCORE-509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16355607#comment-16355607
 ] 

Gary Gregory commented on HTTPCORE-509:
---------------------------------------

The alternative I propose is then this:

{noformat}
diff --git 
a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
 
b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
index 26fb11ea5..51d38e820 100644
--- 
a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
+++ 
b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
@@ -27,6 +27,9 @@

 package org.apache.http.impl.nio.reactor;

+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 import org.apache.http.util.Args;

 /**
@@ -59,7 +62,7 @@ public IOReactorConfig() {
         this.selectInterval = 1000;
         this.shutdownGracePeriod = 500;
         this.interestOpQueued = false;
-        this.ioThreadCount = Runtime.getRuntime().availableProcessors();
+        this.ioThreadCount = Builder.getDefaultMaxIoThreadCount();
         this.soTimeout = 0;
         this.soReuseAddress = false;
         this.soLinger = -1;
@@ -376,6 +379,33 @@ public static Builder copy(final IOReactorConfig config) {

     public static class Builder {

+        private static int DefaultMaxIoThreadCount = -1;
+
+        /**
+         * Gets the default value for {@code ioThreadCount}. Returns
+         * {@link Runtime#availableProcessors()} if
+         * {@link #setDefaultMaxIoThreadCount(int)} was called with a value 
<=0.
+         *
+         * @return the default value for ioThreadCount.
+         * @since 4.4.10
+         */
+        public static int getDefaultMaxIoThreadCount() {
+            return DefaultMaxIoThreadCount > 0 ? DefaultMaxIoThreadCount : 
Runtime.getRuntime().availableProcessors();
+        }
+
+        /**
+         * Sets the default value for {@code ioThreadCount}. Use a value <= 0 
to
+         * cause {@link #getDefaultMaxIoThreadCount()} to return
+         * {@link Runtime#availableProcessors()}.
+         *
+         * @param defaultMaxIoThreadCount
+         *            the default value for ioThreadCount.
+         * @since 4.4.10
+         */
+        public static void setDefaultMaxIoThreadCount(int 
defaultMaxIoThreadCount) {
+            DefaultMaxIoThreadCount = defaultMaxIoThreadCount;
+        }
+
         private long selectInterval;
         private long shutdownGracePeriod;
         private boolean interestOpQueued;
@@ -394,7 +424,7 @@ public static Builder copy(final IOReactorConfig config) {
             this.selectInterval = 1000;
             this.shutdownGracePeriod = 500;
             this.interestOpQueued = false;
-            this.ioThreadCount = Runtime.getRuntime().availableProcessors();
+            this.ioThreadCount = getDefaultMaxIoThreadCount();
             this.soTimeout = 0;
             this.soReuseAddress = false;
             this.soLinger = -1;
{noformat}

> AVAIL_PROCS is autoconfigured based on core count
> -------------------------------------------------
>
>                 Key: HTTPCORE-509
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-509
>             Project: HttpComponents HttpCore
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.4.9
>            Reporter: Elijah Zupancic
>            Priority: Major
>
> In [IOReactorConfig:39|
> https://github.com/apache/httpcomponents-core/blob/92c4c6ff64a9a4a0b0677338c03ebd24bfe1b219/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java#L39
> ], the default value for thread count is based on the detected cores on the 
> system. This is usually acceptable. However, if the library is being run 
> within a container where the reported number of CPUs does not match the 
> actual amount of CPU available, you will see too many threads created in the 
> pool leading to performance degradation.
> Of course a direct user of this library will be able to set this value to a 
> sensible number. However, you will typically see httpcore-nio 4-5 steps down 
> the dependency graph and it is being used by other open source components 
> which in turn are being used by other components.
> I would suggest that we optionally read a system parameter for the value of 
> AVAIL_PROCS. If that system parameter is not available, then we use the value 
> of Runtime.getRuntime().availableProcessors();



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to