AsyncHttpClient 创建太多 AsyncHttpClient-timer 线程



我正在使用AsyncHttpClient 2.3.0和默认配置。

我注意到 AHC 创建了两种类型的线程(来自线程转储(:

1(

AsyncHttpClient-timer-478-1" - Thread t@30390    java.lang.Thread.State: TIMED_WAITING
at java.lang.Thread.$$YJP$$sleep(Native Method)
at java.lang.Thread.sleep(Thread.java)
at io.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:560)
at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:459)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)

2(

AsyncHttpClient-3-4" - Thread t@20320    java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.$$YJP$$epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.epollWait(EPollArrayWrapper.java)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <16163575> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <49280039> (a java.util.Collections$UnmodifiableSet)
- locked <2decd496> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:753)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:409)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)

我预计AsyncHttpClient在引擎盖下使用一些线程。但是在运行了几天后,AsyncHttpClient 创建了 ~500 个 AsyncHttpClient-timer-xxx-x 线程和一些 AsyncHttpClient-x-x。 它的调用不是很密集,每个时期可能也~500次。 仅使用executeRequest(执行请求并获取返回的未来(https://static.javadoc.io/org.asynchttpclient/async-http-client/2.3.0/org/asynchttpclient/AsyncHttpClient.html#executeRequest-org.asynchttpclient.Request-org.asynchttpclient.AsyncHandler-:

<T> ListenableFuture<T> executeRequest(Request request, AsyncHandler<T> handler);

我看过一个关于连接池配置 (https://github.com/AsyncHttpClient/async-http-client/wiki/Connection-pooling( 的页面,但没有关于线程池配置的页面。

这两种类型的线程之间有什么区别,什么会导致创建大量线程?我应该应用任何配置吗?

AHC 有两种类型的线程:

  1. 用于 I/O 操作。 在你的屏幕上,它是AsyncHttpClient-x-x 线程。AHC 创建了其中的2*core_number
  2. 对于超时。 在你的屏幕上,它是AsyncHttpClient-timer-1-1线程。应该是 只有一个

任何不同的数字都意味着您正在创建多个客户端。

来源:GitHub https://github.com/AsyncHttpClient/async-http-client/issues/1658 上的问题

最新更新