Home Operation and Maintenance Nginx What are nginx smooth restart and FPM smooth restart?

What are nginx smooth restart and FPM smooth restart?

May 23, 2023 pm 09:08 PM
nginx fpm

Smooth Restart

GR is the abbreviation of Graceful Restart. It is a mechanism to ensure that forwarding services are not interrupted when the protocol is restarted.
The core of the GR mechanism is that when a device restarts the protocol, it can notify its surrounding devices to maintain stable neighbor relationships and routes to the device within a certain period of time. After the protocol is restarted, peripheral devices assist it in synchronizing information (including various topology, routing and session information maintained by routing/MPLS-related protocols that support GR), restoring the device to the state before the restart in the shortest possible time. state. There will be no route flapping during the entire protocol restart process, and there will be no change in the packet forwarding path. The entire system can forward data without interruption. This process is called a smooth restart.

nginx smooth restart

The Nginx process can be divided into two types: the main process and the worker process. Its smooth restart is controlled through the signal HUB.

What are nginx smooth restart and FPM smooth restart?

Note: On POSIX-compliant platforms, SIGUSR1 and SIGUSR2 are signals sent to a process that represent user-defined situations.

In order to analyze the smooth restart process of nginx in detail, we continue to monitor the nginx process changes.
Send HUP signal

kill -HUP `cat /home/git/nginx/logs/nginx.pid`
Copy after login

What are nginx smooth restart and FPM smooth restart?

What are nginx smooth restart and FPM smooth restart?

What are nginx smooth restart and FPM smooth restart?

##Through observation, a rough smooth restart can be analyzed The process is:

1. The master uses the new configuration to fork out n-1 workers and a new master
2. The new worker handles the new request, and the old worker exits after execution
3. The master reloads the configuration, during Use the new master to take over the service
4. After the master is loaded and configured, the new master switches to the worker working mode
After the smooth restart, the master process number will not change.

nginx smooth upgrade

HUP is only used for smooth restart, loading configuration, etc. If you want to smoothly upgrade the nginx version and reload the compiled binary file, you need to use USR2 Signal.

1. Send USR2 signal

kill -USR2 `cat /home/git/nginx/logs/nginx.pid`
Copy after login

What are nginx smooth restart and FPM smooth restart?

What are nginx smooth restart and FPM smooth restart?##Observe the nginx process, fork out new master and worker, at this time The content of nginx.pid has changed, and the nginx.pid.oldbin file is generated in the logs directory to record the old master pid.

2. Send the WINCH signal to the old master, and nginx worker will stop the service gracefully. That is: stop receiving new requests, but will not terminate requests that are already being processed. After a period of time, all worker processes of the old nginx exit, leaving only the master process, and all user requests are processed by the new nginx process.

kill -WINCH `cat /home/git/nginx/logs/nginx.pid.oldbin`
Copy after login

What are nginx smooth restart and FPM smooth restart?3. Send the QUIT signal to the old master, the old nginx process completely exits, and the smooth upgrade is completed.

kill -QUIT `cat /home/git/nginx/logs/nginx.pid.oldbin`
Copy after login

What are nginx smooth restart and FPM smooth restart?

FPM Smooth Restart

FPM (FastCGI Process Manager) is used to replace most of the additional functions of PHP FastCGI, php5 FPM has been integrated since .3.3. PHP-FPM can be turned on by passing the –enable-fpm parameter in ./configure.

FPM’s smooth restart needs to be controlled by the USR2 signal, but it is quite different from nginx’s smooth restart process.

kill -USR2 `cat /home/git/php/var/run/php-fpm.pid`
Copy after login

What are nginx smooth restart and FPM smooth restart? By continuing to observe the fpm process, we can see that FPM restarts smoothly. It needs to wait for the child process to completely exit before starting the new master and child processes, and then the old master quit.

Use strace for further analysis


What are nginx smooth restart and FPM smooth restart?It is found that the master notifies all child processes to exit, including the child process that is processing the request.

In order to further verify this conclusion, write a server-side sleep script

<?php
exec("sleep 5");
echo &#39;done&#39;;
Copy after login

Use the browser to request this address, and during this period, fpm will be restarted smoothly, and the request will be directly 502.

nginx error log:

[error] 29841#0: *1646 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "localhost"
Copy after login

php bug#60961, there is also a description of fpm's inability to gracefully achieve a smooth restart. Is FPM so low? The answer was no at that time, in fact our goal can be achieved through the process_control_timeout parameter.


process_control_timeout

<p>Set the timeout for the child process to accept multiplexing signals from the main process. Available units: s (seconds), m (minutes), h (hours) or d (days). Default unit: s (seconds). Default: 0 (off). </p> <p>In principle, php-fpm will select an idle fastcgi process to process the request. Before processing, php-fpm will send a signal to fastcgi to prepare the fastcgi process to accept the request processing. However, the fastcgi process is not always able to handle the request, that is, it cannot always respond to the signal (such as suspended animation). At this time, you need to set the time php-fpm leaves for the fastcgi process to respond to the signal. If it times out, php -fpm will think of other ways (such as selecting other fastcgi processes), this is the role of the process_control_timeout parameter. </p> <p>The default value of this parameter is 0, which means it does not take effect. Change it to 10 and re-verify. 502 will no longer appear. </p>

The above is the detailed content of What are nginx smooth restart and FPM smooth restart?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

To allow the Tomcat server to access the external network, you need to: modify the Tomcat configuration file to allow external connections. Add a firewall rule to allow access to the Tomcat server port. Create a DNS record pointing the domain name to the Tomcat server public IP. Optional: Use a reverse proxy to improve security and performance. Optional: Set up HTTPS for increased security.

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

The start and stop commands of Nginx are nginx and nginx -s quit respectively. The start command starts the server directly, while the stop command gracefully shuts down the server, allowing all current requests to be processed. Other available stop signals include stop and reload.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

To solve the "Welcome to nginx!" error, you need to check the virtual host configuration, enable the virtual host, reload Nginx, if the virtual host configuration file cannot be found, create a default page and reload Nginx, then the error message will disappear and the website will be normal show.

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

To register for phpMyAdmin, you need to first create a MySQL user and grant permissions to it, then download, install and configure phpMyAdmin, and finally log in to phpMyAdmin to manage the database.

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

nginx appears when accessing a website. The reasons may be: server maintenance, busy server, browser cache, DNS issues, firewall blocking, website misconfiguration, network connection issues, or the website is down. Try the following solutions: wait for maintenance to end, visit during off-peak hours, clear your browser cache, flush your DNS cache, disable firewall or antivirus software, contact the site administrator, check your network connection, or use a search engine or web archive to find another copy of the site. If the problem persists, please contact the site administrator.

How to communicate between docker containers How to communicate between docker containers Apr 07, 2024 pm 06:24 PM

There are five methods for container communication in the Docker environment: shared network, Docker Compose, network proxy, shared volume, and message queue. Depending on your isolation and security needs, choose the most appropriate communication method, such as leveraging Docker Compose to simplify connections or using a network proxy to increase isolation.

See all articles