Multithreaded server programming model

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

  1. connection establishment
  2. broken link
  3. message arrives
  4. After the message is sent, you don't need to care about low-traffic services

one loop per thread

benefit:

  1. The number of threads is basically fixed and will not be created and destroyed frequently
  2. Load can be easily adjusted
  3. The thread in which the IO event occurs is fixed, and there is no need to consider concurrency.

concurrent design

  1. Iteration server
  2. accept + fork
  3. thread per connection -> not suitable for short link service, system burden is heavy
  4. IO multiplexing (must have non-blocking and Buffer)
  5. Multithreaded Reactor -> + Worker Thread Pool

eventloop as non-blocking IO and timer, thread poll as computing model.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325075830&siteId=291194637