Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does AsyncHttpClient knows how many threads to allocate for all the HTTP requests

I'm evaluating AsyncHttpClient for big loads (~1M HTTP requests). For each request I would like to invoke a callback using the AsyncCompletionHandler which will just insert the result into a blocking queue

My question is: if I'm sending asynchronous requests in a tight loop, how many threads will the AsyncHttpClient use? (I know you can set the max but apparently you take a risk of losing requests, I've seen it here)

I'm currently using the Netty implementation with these versions:

  • async-http-client v1.9.33
  • netty v3.10.5.Final

I don't mind using other versions if there are any optimization in later versions

EDIT:

I read that Netty uses the reactor pattern for reacting to HTTP responses which means it allocates a very small number of threads to act as selectors. This also means that the number of allocated threads doesn't increase with high requests volume. However that contradicts the need to set the max number of connections.

Can anyone explain what I'm missing?

Thanks in advance

like image 403
Gideon Avatar asked Feb 16 '16 11:02

Gideon


1 Answers

The AsyncHttpClient client (and other non-blocking IO clients for the matter), don't need to allocate a thread per request, and the client need not resize its thread pool even if you bombard it with requests. You do initiate many connections if you don't use HTTP keep-alive, or call multiple hosts, but it can all be handled by a single threaded client (there may be more than one IO thread, depending on the implementation).

However, it's always a good idea to limit the max requests per host, and max requests per domain, to avoid overloading a service on a specific host, or a site, and avoid getting blocked. This is why HTTP clients add a maxConnectionsPerXxx setting.

like image 164
Eran Harel Avatar answered Sep 27 '22 15:09

Eran Harel