tags: netty
The center of this article
Let's first look at the thread communication model of BIO
Explanation
Off-topic: Throughout the process, the threads are synchronized from the user state to the kernel state to the user state, and the user thread has been waiting until the result returns
The Reactor model (reactor mode) is divided into 3 categories: single-threaded, multi-threaded, master-slave multi-threaded
1. Single-threaded Reactor model

Explanation
Disadvantages:
Although we have realized that Client requests are not blocked and requests are processed asynchronously, you can see in the single figure that receiving requests and assigning handlers is still single-threaded processing, and there are still problems.
1. Single-thread wasting CPU resources
2. If there is a processing exception in the single-threaded part of the figure, there will be blocking, and there will be a bottleneck when the Client is too concurrent
So it attracts multiple threads
2. Multi-threaded Reactor model

Explanation
defect:
We see that the acceptor thread is still in a single-threaded receiving state. If there is a large IO operation, it will inevitably affect other
Thus introducing master-slave multithreading
3. Master-slave multi-threaded Reactor model
Explanation:
Compared with multi-threading, Reactor is divided into mainReactor and subReactor by one
2. mainReactor: mainly used to receive client requests, pass the received SocketChannel to subReactor, and subReactor is responsible for communication with the client
3. Benefits: mainReactor is only responsible for receiving client requests and adapting subReactor and not responsible for real communication. Each subReactor thread has independent Selector, thread, event logic, and will not block other threads because of large IO
1. Mode correspondence:
Netty server uses "multi-reactor thread mode"
MainReactor ———— A NioEventLoop in bossGroup (NioEventLoopGroup)
SubReactor ———— A NioEventLoop in workerGroup (NioEventLoopGroup)
acceptor ———— ServerBootstrapAcceptor
ThreadPool ———— User-defined thread pool
2. Netty startup process (extracted from the network, not verified yet, probably the process should be correct)
This chapter introduces netty's threading model. Before talking about netty's threading model, we first write an example using Java's NIO to imitate netty's threading model. Code address:GitHub code T...
When we discuss the Netty threading model, we usually first think of the classic Reactor threading model. Although different NIO frameworks have different implementations of the Reactor mode, they ess...
1. background 1.1. Amazing performance dataData analysis and enterprise architectureData-driven personalized recommendation under JD 618 promotionHow to build an artificial intelligence product resear...
Two common business scenarios CPU-intensive: computing type; IO-intensive: waiting type, such as relying on other microservices and databases; CPU intensive Keep the current thread model and reuse the...
Introduction to Netty Netty is a high-performance, highly scalable asynchronous event-driven network application framework, which greatly simplifies network programming such as TCP and UDP client and ...
The core concept in Netty isEvent loop (EventLoop), Which is actually Reactor in Reactor mode,Responsible for monitoring network events and calling event handlers for processing.In the 4.x version of ...
Zero copy hard driver - kernel buffer - protocol engine only DMA copy avoids cpu copy There was actually a cpu copy of kernel buffer - socket buffer, but the copied information can rarely be ignored; ...
Introduction to Netty Netty is a high-performance, high-scalable asynchronous event-driven network application framework, which greatly simplifies network programming such as TCP and UDP clients and s...
Why use Netty Netty is an asynchronous event-driven web application framework for rapid development of maintainable high-performance and high-profile servers and clients. Netty has the advantages of h...
Event cycle group All I / O operations in Netty are asynchronous, and the asynchronous execution results are obtained by channelfuture. Asynchronously executes a thread pool EventLoopGroup, it ...