0

I am trying to set an event loop group while creating AsyncHttpClient but I would like to understand the input parameters for creating and setting an eventLoop.

NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(32, Executors.newScheduledThreadPool(33));
AsyncHttpClient asyncHttpClient = return asyncHttpClient(
    config().setConnectTimeout(30000).setRequestTimeout(5000).setEventLoopGroup(eventLoopGroup));

For new NioEventLoopGroup, what's the difference between the first parameter and the threadpool size of the Executor? When I set this value and inspect the executor, 32 threads are "New I/O" threads and 1 thread for the thread pool to perform requests. This results in timeouts. What is the best way to set the thread pool size to N threads?

user1429322
  • 1,266
  • 2
  • 24
  • 38

1 Answers1

0

The first arg nThreads is an amount of eventloops to create and the second one is an executor(with constant pool of threads in your case). When a group called to exec some tasks it puts them in each loop consequently. Executor puts loop in the thread from pool and loop remains working in that thread till the forced shutdown of the executor or thread specifically.(the 32 used threads from the pool you see in an inspector is probably because loops already running/waiting in them)

If executor somehow lost some threads or block them or your assigned lower amount of threads then nThreads - remaining loops will be queueing received tasks but do nothing.

I actually suggest to use plain executor that will create all the needed amount of threads and you wont stumble upon any loop missing it's thread.

J. Murray
  • 1,460
  • 11
  • 19
Artem Lisun
  • 52
  • 1
  • 6