Netty Threading Model
About Java NIO reactor mode http://my.oschina.net/xinxingegeya/blog/339027
The following is the evolution of the threading model
Thread per Connection
Thread per Connection: This is the threading model used by traditional Java network programming scenarios before NIO. There is a main loop, socket.accept blocking wait, when a connection is established, a new thread is created/taken from the thread pool, and the socket connection is left to the new thread for full processing. the advantages and disadvantages of this scheme are obvious, the advantage is simple implementation, the disadvantage is that the scalability of the scheme is limited by the number of threads.
Reactor in single Thread
Reactor in single Thread: With NIO, the IO multiplexing mechanism can be used. We extracted a single-threaded version of the reactor model, the timing diagram is shown below, the scheme has only one thread, all socket connections are registered on the reactor, by a thread full responsibility for all tasks. It is simple to implement and is not limited by the number of threads. This scenario is limited to use scenarios, is suitable only for IO-intensive applications, is not suitable for CPU-intensive applications, and is suitable for CPU resource intensive applications.
http://my.oschina.net/xinxingegeya/blog/339027
Reactor + Thread Pool
Reactor + thread Pool: Scenario 2 is constrained by usage scenarios, but in order to use CPU resources more fully, a logical processing thread pool is extracted. Reactor is only responsible for IO tasks, and the thread pool is responsible for all other logic processing. Although the program can take full advantage of CPU resources, this scenario has more than two context switches in and out of the thread pool.
Reactors in Threads
Reactors in Threads: Based on scenario 3 disadvantage considerations, divide the reactor into two parts. Main reactor is responsible for connection tasks (accept, connect, etc.), and Sub reactor is responsible for IO, logic tasks, Mina and Netty threading models. The scheme is very adaptable and can adjust the number of sub reactor to the application of CPU resource tension, while CPU-intensive tasks can be referred to the thread pool in the business processing logic, such as Scenario 5. This scenario has a less obvious drawback, that the session is not prioritized, and all sessions are treated equally evenly across all the threads, which can cause the priority low-resource session to clog the high-priority session, But it seems that Netty and Mina did not optimize for this.
Reactors in Threads + threads pool
Reactors in Threads + threads pool: This is also the model used by my company application framework, which can be more flexible to adapt to all the application scenarios: Adjust the number of reactor, adjust the size of the thread pool, etc.
==========================end==========================
Netty Threading Model