javaopensearchapache-httpcomponentsapache-httpclient-5.x

What is the difference between I/O Reactor Config ioThreadCount and PoolingAsyncClientConnectionManager maxConnTotal?


Following up on my previous question here: What is the difference between different apache-httpclient5 setup config provided by Apache HttpClient 5?

I/O Reactor Config is the lowest level of config (as this config is applied before establishing any connections to the server) provided by Apache HttpClient 5 to manage how you interact with the server. Following that, Connection Config comes into the picture which is basically the configuration to modify how each individual connection behaves. Then comes RequestConfig, in which, you can modify how each individual http requests behaves even though the client and server are communicating using the same connection.

So, my question is if I/O Reactor sets up various workers before any connections is established and then later, connection pool is setup, which the client can use to requests connections from it, to connect to the server.

  1. Is there a separate thread pool for I/O Reactor and the connection thread pool? If that's the case, does I/O Reactor ioThreadCount specifies the max threads in the I/O Reactor thread pool? And, PoolingAsyncClientConnectionManager maxConnTotal defines the max connections or max threads in the thread pool that can be used to communicate with the server?
  2. Does I/O Reactor role is to store incoming requests coming to the client in a queue, and then dispatches those requests to the client as the requests are taken care of? If not, how does I/O Reactor and the connection pool works together?
  3. If the recommended count for ioThreadCount is the number of processors available to the JVM, then is the recommendation for maxConnTotal be also the same?
  4. What is IOReactorConfig selectInterval? The doc says that "Determines time interval at which the I/O reactor wakes up to check for timed out sessions and session requests." Does this mean that the underlying I/O reactor threads are sleeping and they need to wake up?

Solution

    1. I/O reactor maintains a small pool of I/O dispatch threads to manage a large number of non-blocking I/O channels. By default the number of threads in that pool is equal to the number of CPU cores. In other words the I/O operations should get distributed evenly across all processing units. Generally one should never change ioThreadCount parameter. The connection manager maintain a pool of connection references that can be leased in order to execute message exchanges. Connection managers DO NOT manage threads.

    2. Connection managers manage connection setup and re-use and also ensure the same connection can be leased by a single consumer at a time. I/O events are processed by the I/O reactor. Connection managers manage resources. I/O reactors execute a communication protocol.

    3. No. Not all all. A single I/O dispatch can handle multiple (thousands of) I/O channels.

    4. This is basics of Java NIO. I/O selectors block and fire only once there is an I/O event on one of their registered channels. Sometime one needs the selectors to unblock (wake up) even there is no I/O and do some extra chores such as manage idle channels and trigger socket timeout for such channels. One generally should never f**k around with this parameter unless one really needs more granular socket timeouts (less than 1 second) at the cost of more dead polar bears.