Java – asynchronous HTTP client (ning) create more threads?

I am using Ning async HTTP client to realize the advantages of non blocking Doing an apple to Apple test (non blocking and blocking), I found that the non blocking version is providing more request samples, but the asynchronous HTTP client is creating more threads than its blocking counterpart Is this expectation or something I lost?

The following are the pressure test figures

Async Http Client
jMeter - 2 threads,120 seconds,1 sec ramp up
Peak threads : 270
Heap usage: 600mb
Peak cpu usage: 30%
Total samples: 18228

Blocking version
jMeter - 2 threads,1 sec ramp up
Peak threads: 118
heap usage: 260mb
cpu usage: 18%
total samples: 1472

I am creating a connection thread pool (reuse them)

AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
builder.setRequestTimeoutInMs(2000);
builder.setMaximumConnectionsPerHost(10);
builder.setMaximumConnectionsTotal(100);
client = new AsyncHttpClient(builder.build());

Is there anything I miss here? I tried to look at the thread dump to see what the thread was created, but I couldn't find anything useful I bet that each HTTP connection generated has a thread to trigger a callback when the I / O of the asynchronous HTTP client completes

Solution

Editor 11 / 16 / 2015

Looks like we've moved See this line, where you can change the threadfactory used If not set, it appears that it uses the default value This is used by channelmanager here

You can also set it on a simple client, as shown here

Original w / dead link deleted

Quick look at the code - it seems that the executor service used by the application thread pool is a cached thread pool, which creates threads as needed You can use the setter on the builder to set the executor service used by the client

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>