Where to put thread pools?

"이희승 (Trustin Lee)" trustin at gmail.com
Fri Jun 10 01:19:35 EDT 2011


Hi,

Never use MATPE to construct a channel factory.  Use 
Executors.newCachedThreadPoolExecutor() unless you understand how 
exactly Netty uses the thread pool.

Also, you are using the OIO transport, which means a connection will 
always have its own thread for I/O.  So, I don't think you will need an 
ExecutionHandler in this case.

If you are using the NIO transport and you are doing something takes 
relatively long time in your handler, you will need an ExecutionHandler 
in the pipeline.

The number of I/O threads and the size of the OMATPE should be 
determined by the user via performance tests.

HTH

On Mon 06 Jun 2011 01:57:53 PM KST, Marc-André Laverdière wrote:
> Hello everyone,
> 
> I'm having a bit of a doubt, and I think I've been using an overkill
> amount of threads in my application.
> 
> So here is the code snippet for my channel factory intialization.
> 
> NUM_THREADS = config.getInt(SERVER_THREADS);
> ThreadPoolExecutor WORKER_THREAD_POOL = new
> MemoryAwareThreadPoolExecutor(NUM_THREADS, ...);
> ThreadPoolExecutor basePool = new
> MemoryAwareThreadPoolExecutor(Math.max(1, NUM_THREADS/10), ...);
> channelFactory = new OioServerSocketChannelFactory(basePool,
> WORKER_THREAD_POOL);
> 
> And here is what the pipeline factory creates:
> ...
> pipeline.addLast(HANDLER_EXECUTOR_NAME, new ExecutionHandler(executor));
> ...
> 
> Please note that this is the same executor than the one that we used above.
> Before I jump to conclusions, let me ask the list:
> 1) Is there any way that we can set an upper bound in the number of
> threads created across all thread pools?
> 2) What is the optimal architecture? Here are the 2 ideas I have
> 2.1 Base Thread pool 2* # of cores, worker pool the same size, and a
> MATPE of size NUM_THREADS used in an ExecutionHandler
> 2.2 Base Thread pool 2* #of cores, MATPE of size NUM_THREADS as the
> worker pool, and NO ExecutionHandler later.
> 
> Regards,



-- 
Trustin Lee, http://gleamynode.net/


More information about the netty-users mailing list