Multithreaded server programming model
The value of multithreading lies in the performance of multi-core processors, and a single-core state machine is the most efficient.
Improve average response time
The essence of TCP network programming
Handling three and a half events
- connection establishment
- broken link
- message arrives
- After the message is sent, you don't need to care about low-traffic services
one loop per thread
benefit:
- The number of threads is basically fixed and will not be created and destroyed frequently
- Load can be easily adjusted
- The thread in which the IO event occurs is fixed, and there is no need to consider concurrency.
concurrent design
- Iteration server
- accept + fork
- thread per connection -> not suitable for short link service, system burden is heavy
- IO multiplexing (must have non-blocking and Buffer)
- Multithreaded Reactor -> + Worker Thread Pool
eventloop as non-blocking IO and timer, thread poll as computing model.