autoreload 线程 进程管理 并发的处理方法 nginx 热加载
小结:
1)工作进程处理请求;主进程监听配置,校验有效后,开启新的工作进程;旧工作进程不再接收请求。
cpython/socketserver.py at main · python/cpython https://github.com/python/cpython/blob/main/Lib/socketserver.py
For request-based servers (including socket-based): | |
- client address verification before further looking at the request | |
(This is actually a hook for any processing that needs to look | |
at the request before anything else, e.g. logging) | |
- how to handle multiple requests: | |
- synchronous (one request is handled at a time) | |
- forking (each request is handled by a new process) | |
- threading (each request is handled by a new thread) |
Beginner’s Guide https://nginx.org/en/docs/beginners_guide.html
nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes. The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores (see worker_processes).
Changes made in the configuration file will not be applied until the command to reload configuration is sent to nginx or it is restarted. To reload configuration, execute:
nginx -s reload
Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit.