Because this process is a high-CPU and high-memory operation, not a high-hard disk IO operation. In other words, this process tests the CPU performance. And we know that computers do not have real multi-processes or multi-threads, they are all simulated through CPU scheduling. So for high-CPU operations, it is best to use a single-process or single-threaded method (multi-core can be considered to increase). This is the most efficient method, because it avoids the consumption caused by switching back and forth between threads or processes.
You can refer to the architecture of Nginx for this. The high load of Nginx is also completed in a single process.
CPython’s multi-threading is not “real” multi-threading (see GIL for details). If you don’t change the language, the solution is to multi-process, with a load balancing (haproxy or the like) in front.
There are multiple models for handling concurrent connections. Multithreading is one type, and the non-blocking I/O + multiplexing represented by epoll is also one type. As long as it is used correctly, read/write after a new connection comes in will not block even for a small period of time.
Experienced drivers in the early years have all read Dan Kegel’s The C10K Problem, which explains various concurrency processing models. If your English is passable, I still recommend you read it. Oh, by the way, if you are learning concepts that do not involve various technical enhancements made in the actual system to handle large concurrency, then Richard Stevens' "Unix Network Programming" explains it more clearly, and the Chinese translation is also easier to read. .
Because this process is a high-CPU and high-memory operation, not a high-hard disk IO operation. In other words, this process tests the CPU performance. And we know that computers do not have real multi-processes or multi-threads, they are all simulated through CPU scheduling. So for high-CPU operations, it is best to use a single-process or single-threaded method (multi-core can be considered to increase). This is the most efficient method, because it avoids the consumption caused by switching back and forth between threads or processes.
You can refer to the architecture of Nginx for this. The high load of Nginx is also completed in a single process.
CPython’s multi-threading is not “real” multi-threading (see GIL for details). If you don’t change the language, the solution is to multi-process, with a load balancing (haproxy or the like) in front.
There are multiple models for handling concurrent connections. Multithreading is one type, and the non-blocking I/O + multiplexing represented by epoll is also one type. As long as it is used correctly, read/write after a new connection comes in will not block even for a small period of time.
Experienced drivers in the early years have all read Dan Kegel’s The C10K Problem, which explains various concurrency processing models. If your English is passable, I still recommend you read it. Oh, by the way, if you are learning concepts that do not involve various technical enhancements made in the actual system to handle large concurrency, then Richard Stevens' "Unix Network Programming" explains it more clearly, and the Chinese translation is also easier to read. .