An overview of the
- Reactor thread models can be divided into the following categories
-
Single Reactor Single thread
-
Single Reactor multithreading
-
Multireactor multithreading
-
Single Reactor Single thread
-
Features:
- A single thread does all the work of establishing a connection, processing the request, and sending back the request
-
Disadvantages:
- Unable to utilize multi-core CPUS
- Because it is single-threaded, if a request takes too long to process, it will block for a long time
-
Advantages:
- Single thread running, no locking, all operations are serial
-
Application: Redis thread model
Single Reactor multithreading
- Features:
- The Reactor is a master thread that processes event-generating sockets and distributes them to the corresponding processors
- The corresponding processor will use the thread pool implementation, multithreading processing
- Disadvantages:
-
There are data security issues, multithreading
-
The main thread needs to handle all network events, which can easily cause congestion during high concurrency!
-
Multireactor multithreading
- Features:
- The main thread is used to establish a connection, bind the socket to another thread, and then the main thread is left alone. Subsequent NETWORK I/O events are handled by the thread to which the socket is bound
- Application:
-
Nginx Reactor Multiple processes
-
Netty Multiple Reactor Multiple threads
-
Reference:
Mp.weixin.qq.com/s/px6-YnPEU…