About Netty's IO Strategy

610 views
Skip to first unread message

Bongjae Chang

unread,
Dec 5, 2011, 11:19:32 PM12/5/11
to Netty project
Hi,

I am a newbie. When I reviewed Netty's guides and some codes, I had some questions.

NioServerSocketChannelFactory has 3 params.
1. boss executor
2. worker executor
3. worker count

About 2 and 3, I have questions.
---
Document says:
Boss threads are acquired from the bossExecutor, and worker threads are acquired from the workerExecutor. Therefore, you should make sure the specified Executors are able to lend the sufficient number of threads. It is the best bet to specify a cached thread pool.
...
Worker threads - One NioServerSocketChannelFactory can have one or more worker threads. A worker thread performs non-blocking read and write for one or more Channels in a non-blocking mode.
---
And default worker count is 2 * the number of available processors.

1. When I reviewed codes, Netty creates selectors with worker counts for reading and writing IO and NIOWorkers are executed in worker executor.
If I am understanding correctly, read/write IO work will be executed in these selector threads.
And worker executor's max threads number can't exceed worker's counts. Is it right?
Then a cached thread pool's meaning is only saving redundant threads(from 0 to worker count).

2. If a user overrides SimpleChannelUpstreamHandler#messageReceived() incorrectly, so the method will be blocked or have a long running logic,
the selector thread will be also blocked. Right?

First, I thought Netty's worker threads were only for Read/Write IO logic associated with channel or connection which were delegated by the selector thread.
But Netty's worker threads look like selector threads.
So I am confusing selector thread and worker thread's relations.

Could you please advice me if I am misunderstanding?

Thanks in advance.

Regards,
Bongjae Chang

Norman Maurer

unread,
Dec 7, 2011, 2:10:17 AM12/7/11
to ne...@googlegroups.com
Hi there,

comments inside..

2011/12/6 Bongjae Chang <bongja...@gmail.com>

Hi,

I am a newbie. When I reviewed Netty's guides and some codes, I had some questions.

NioServerSocketChannelFactory has 3 params.
1. boss executor
2. worker executor
3. worker count

About 2 and 3, I have questions.
---
Document says:
Boss threads are acquired from the bossExecutor, and worker threads are acquired from the workerExecutor. Therefore, you should make sure the specified Executors are able to lend the sufficient number of threads. It is the best bet to specify a cached thread pool.
...
Worker threads - One NioServerSocketChannelFactory can have one or more worker threads. A worker thread performs non-blocking read and write for one or more Channels in a non-blocking mode.
---
And default worker count is 2 * the number of available processors.

1. When I reviewed codes, Netty creates selectors with worker counts for reading and writing IO and NIOWorkers are executed in worker executor.
If I am understanding correctly, read/write IO work will be executed in these selector threads.
And worker executor's max threads number can't exceed worker's counts. Is it right?

Right..
 
Then a cached thread pool's meaning is only saving redundant threads(from 0 to worker count).
 
The cached ThreadPool is used to guarantee that you never see any starvation.
 

2. If a user overrides SimpleChannelUpstreamHandler#messageReceived() incorrectly, so the method will be blocked or have a long running logic,
the selector thread will be also blocked. Right?

Right... If you need to execute blocking logic you need to insert an ExecutionHandler in the ChannelPipeline which will "off-load" the tasks to another ThreadPool.
 

First, I thought Netty's worker threads were only for Read/Write IO logic associated with channel or connection which were delegated by the selector thread.
But Netty's worker threads look like selector threads.
So I am confusing selector thread and worker thread's relations.

Could you please advice me if I am misunderstanding?

In Netty the "BossExecutor" is responsible to call Socket.accept() and if this returns non null register it with an IO-Worker. The NioWorker does "select" and then do the IO logic. So you observation is correct.

 

Thanks in advance.

Regards,
Bongjae Chang

Hope this helps,
Norman
 

Bongjae Chang

unread,
Dec 7, 2011, 4:23:53 AM12/7/11
to ne...@googlegroups.com
Hi Norman,

Thank you for your kindness. I understood clearly.

Thanks!

Regards,
Bongjae Chang
Reply all
Reply to author
Forward
0 new messages