Thanks for your response, Oleg!
Setting defaultMaxPerRoute and maxTotal on the
PoolingClientAsyncConnectionManager allowed me to create a large number of
concurrent requests. Up to about 4000 it runs well. Going to 5000 (I was trying
to get to 10,000 to see where the boundaries are) results in the following
exception:
Exception in thread "I/O dispatcher 2" java.lang.NoClassDefFoundError: Could
not initialize class sun.nio.ch.FileDispatcher
at sun.nio.ch.SocketDispatcher.preClose(SocketDispatcher.java:41)
at
sun.nio.ch.SocketChannelImpl.implCloseSelectableChannel(SocketChannelImpl.java:709)
at
java.nio.channels.spi.AbstractSelectableChannel.implCloseChannel(AbstractSelectableChannel.java:201)
at
java.nio.channels.spi.AbstractInterruptibleChannel.close(AbstractInterruptibleChannel.java:97)
at
org.apache.http.impl.nio.reactor.IOSessionImpl.close(IOSessionImpl.java:215)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.closeActiveChannels(AbstractIOReactor.java:544)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.hardShutdown(AbstractIOReactor.java:579)
at
org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:309)
at
org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106)
at
org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:601)
at java.lang.Thread.run(Thread.java:662)
Are there any other settings to consider when processing a large number of
concurrent requests? The specific scenario I'm testing with is reading JSON
responses (about 2K each) where each response takes about a second to complete
(i.e. the test server holds for a second before returning).
Thanks,
Rossen
----- Original Message -----
> From: "Oleg Kalnichevski" <[email protected]>
> To: "HttpClient User Discussion" <[email protected]>
> Sent: Thursday, June 21, 2012 5:53:37 PM
> Subject: Re: Concurrent asynchronous HTTP exchanges
>
> On Thu, 2012-06-21 at 13:20 -0700, Rossen Stoyanchev wrote:
> > I've been experimenting with the "Concurrent asynchronous HTTP
> > exchanges" sample here:
> > http://hc.apache.org/httpcomponents-asyncclient-dev/examples.html
> >
> > I submit 20 requests to a test server that takes 1 second to
> > respond. I see two requests complete every second and it takes 10
> > seconds in total to complete all 20 requests. So it looks like
> > there is a bottleneck.
> >
> > I happen to have the current thread name included in log messages
> > and I can see requests completing in one of two threads ("I/O
> > dispatcher 1" and "I/O dispatcher 2"). Could it be that some
> > thread count needs to increase? I expected with NIO the number of
> > threads could be kept lower than with blocking I/O.
> >
> > My question is what settings on DefaultHttpAsyncClient would you
> > recommend to configure for processing a larger number of
> > concurrent requests?
> >
> > I tried this but it didn't make a difference:
> >
> > IOReactorConfig ioReactorConfig = new IOReactorConfig();
> > ioReactorConfig.setIoThreadCount(20);
> > HttpAsyncClient httpclient = new
> > DefaultHttpAsyncClient(ioReactorConfig);
> >
> >
> > thanks,
> > Rossen
> >
>
> Hi Rossen
>
> Per default HttpAsyncClient allows only two concurrent connections to
> the same host (same route to be exact) as required by the HTTP
> specification. This is a spec compliant behavior.
>
> You might want to increase this number using connection manager
> settings
> if you need higher concurrency. The number of dispatcher threads
> should
> be equal to the number of physical CPU cores of your system. This is
> done automatically by default using
> Runtime.getRuntime().availableProcessors() call.
>
> If you set the max connections per route number to ten, the total
> execution time of 20 requests in your example should drop to
> approximately 2 seconds.
>
> Hope this helps
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]