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

寵の児 提交于 2019-12-03 06:55:23
Eran Harel

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.

AHC has two types of threads:

  1. For I/O operation. On your screen, it's AsyncHttpClient-x-x threads. AHC creates 2*core_number of those.
  2. For timeouts. On your screen, it's AsyncHttpClient-timer-1-1 thread. Should be only one.

And as you mentioned:

maxConnections just means number of open connections which does not directly affect the number of threads

Source: issue on GitHub: https://github.com/AsyncHttpClient/async-http-client/issues/1658

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!