Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Netty uses thread pools?

Tags:

java

netty

Can you please explain how Netty uses thread pools to work? Do I understand correctly, that there are two kinds of thread-pools: boss and worker. Boss ones are used to do I/O and worker are used to call user callbacks (messageReceived) to process data?

like image 307
Vladislav Rastrusny Avatar asked Mar 29 '11 14:03

Vladislav Rastrusny


People also ask

How many threads does Netty use?

However, if Reactor Netty is used for both client and server, the two share event loop resources by default. Typically, you have 4 worker threads, which are shared between both server processing and client-side communication with other resources.

How does thread pool works?

In computer programming, a thread pool is a software design pattern for achieving concurrency of execution in a computer program. Often also called a replicated workers or worker-crew model, a thread pool maintains multiple threads waiting for tasks to be allocated for concurrent execution by the supervising program.

Is Netty single threaded?

Netty client uses only one thread.


1 Answers

This is from NioServerSocketChannelFactory document

A ServerSocketChannelFactory which creates a server-side NIO-based ServerSocketChannel. It utilizes the non-blocking I/O mode which was introduced with NIO to serve many number of concurrent connections efficiently.

How threads work
There are two types of threads in a NioServerSocketChannelFactory; one is boss thread and the other is worker thread.

Boss threads
Each bound ServerSocketChannel has its own boss thread. For example, if you opened two server ports such as 80 and 443, you will have two boss threads. A boss thread accepts incoming connections until the port is unbound. Once a connection is accepted successfully, the boss thread passes the accepted Channel to one of the worker threads that the NioServerSocketChannelFactory manages.

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.

In Nio model, bossThread take care all bounded socket(listen socket), workerThread take care Accepted-socket (included IO and call event method such as messageReceived).

like image 126
secmask Avatar answered Sep 29 '22 13:09

secmask