Does Async http client (ning) create more threads?

I am using ning async http client to achieve non-blocking kindness. When checking apples and apples (without blocking against blocking), I see that the non-blocking version serves more sample requests, however the async-http client creates more threads than its blocking copy. Is this expected or something that I am missing?

Here are the numbers from the stress test

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, 120 seconds, 1 sec ramp up Peak threads: 118 heap usage: 260mb cpu usage: 18% total samples: 1472 

I am creating a connection thread pool (reusing them)

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

Is something missing here? I tried looking at the thread dump to see what creates the threads, but didn't find anything useful. My bet is that for each HTTP connection, a thread is created to trigger a callback when I / O is completed in the async http client.

+6
source share
1 answer

EDIT 11/16/2015

It looks like the repo has moved. See this line where you can change the ThreadFactory used. If this is not set, it looks like it uses the default value. This is used by ChannelManager here .

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

ORIGINAL with deleted links

Quick code review - it looks like the application thread pool uses the Executor service, which is a pool of cached threads that creates threads as needed. You can install the executor service that your client uses using the installer in the builder.

+11
source

Source: https://habr.com/ru/post/915110/


All Articles