AsyncHttpClient 创建了过多的 AsyncHttpClient 计时器线程

AsyncHttpClient creates too many AsyncHttpClient-timer threads

我正在使用 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.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

上的问题