What will happen to the request being transmitted at the moment of configuration reload
At the moment of configuration reload, will the requests being transmitted be directly cut off? By default, they will not. The difference between reload (reload) and restart (restart) is here: during reload, the main process does not exit, it starts up a batch of new worker processes according to the new configuration, hands over the new connections to them, and at the same time, allows the old worker processes to enter the exit process—the old processes no longer accept new connections, but will continue to handle the established connections until these connections end on their own.So short requests and long requests are safe in the moment of overload. The only case where they will be cut off is when you set an exit time limit for the old process, and once the time limit is reached, the process will try to close all currently open connections to end itself.
Which type of connection does the exit time limit control
This instruction is quite direct in the nginx core module documentation: worker_shutdown_timeout is the configuration limit for the graceful shutdown of worker processes, after the time limit expires, nginx will attempt to close all currently open connections to complete the exit;This command was introduced from version 1.11.11, the scope is the main configuration layer. Note that it manages objects - already established connections, not new requests.The default value is not set, which means allowing the old process to wait until all connections naturally end. This default value itself explains the trade-off: no time limit is set, and the exit time is uncontrollable;Set a time limit, and the requests in transmission will bear the cost of being cut off.
Which scenarios will be affected by the time limit
The three types are the most typical. Large file upload: a single transfer may take tens of seconds or more, the time limit is shorter than the transfer time, and the user sees the upload fail halfway through, and retries will collide with the next round of reloading. Long connections and streaming responses: the purpose of connections like server push and event stream is to maintain them for a long time, and any time limit will actively cut them off. Queue-type task interface: the request itself takes a long time to process, and after the timeout is cut off, the client cannot know whether the server has completed the processing, and it is easy to submit duplicates. On the contrary, almost unaffected are the short requests that break off in a flash and the idle connections that have completed the response.
What are the consequences of setting it too short and too long
The consequence of a very short time limit is a perceptible failure: the connection is forcibly closed, the client appears to be interrupted, and no clear reason can be seen in the logs because this is an action executed according to design.The consequences of a too long time limit or not setting one are more concealed: the old work process lingers for a long time, the memory usage does not decrease, and the old and new configurations coexist at the same time - the flow control threshold, cache rules, and certificates are inconsistent in the two groups of processes, and when troubleshooting, looking at the same configuration, two different behaviors are obtained.This is particularly worth noting for memory-sensitive scenarios, the memory usage of the Go technology stack site itself is about 80% lower than that of PHP-like programs, and the additional usage of the滞留进程processes is therefore more obvious in the overall cost;The page loading speed is directly related to whether it can stably bear the load of about 5 million PV levels on a single machine, and the optimization of the new configuration will take effect completely in the next round when the old process has not been cleaned up completely.The reasonable approach is to set the time limit slightly longer than the normal longest request time in the business and avoid frequent reloads within the change window.
What is the verification method after the modification
First, perform grammar and configuration checks to confirm that the new configuration can be loaded; then perform a reload instead of a restart to retain ongoing transfers. After the reload, confirm three things: the new work process has started accepting tasks according to the new configuration;The old process is in the exit state and the number is decreasing; if an exit time limit is set, observe whether it reaches zero at the expected time. Also note one thing when deploying with Docker images: the process signals in the container must be able to reach the main process, and the reload action will be effective; directly rebuilding the container is considered a restart, which will cut off all connections, and it is not the same as a reload.AnQiCMS (AnQi CMS) listens on the default port 8001, and after the reverse proxy configuration is changed, it should be verified in the same order: first check the configuration, then reload, and then confirm from outside that the new rules are effective and that old requests have not been interrupted.
Common questions
Question: Which one should be chosen, reload or restart?Answer: Choose reload if only the configuration content is changed, and choose restart if it is necessary to reload the program itself. Reload retains the connections in transmission, while restart does not.
Question: How can you tell if the old process is still alive?Answer: Look at the number of working processes. It is a normal phenomenon for the number of processes to briefly appear twice after a reload, and then fall back to one batch; if it does not fall back for a long time, it means that there are still connections that have not ended.
Question: Should a timeout be set for long connection business?Answer: Make it wider or not set. This type of connection does not have a natural end time, the short limit is equal to regular interruptions, unless you have a clear switching window.