Home Backend Development PHP Tutorial Solve the problem of excessive server memory resource consumption caused by too many php-fpm processes in CentOS7

Solve the problem of excessive server memory resource consumption caused by too many php-fpm processes in CentOS7

Jan 13, 2020 pm 02:03 PM
php-fpm

Foreword:

The server memory usage has been high recently. After checking, it was found that it may be related to the excessive number of php-fpm processes. This article records my process of optimizing the php-fpm configuration file and adds some knowledge related to php-fpm.

What is php-fpm:

php-fpm is the FastCGI process manager, used to control php's memory and processes.

Operating environment:

CentOS 7

Problem check:

First check the total number of php processes:

pstree|grep php-fpm
Copy after login

Echo:

|-php-fpm---20*[php-fpm]
Copy after login

According to the echo information, there are 20 php-fpm processes during the query.

You can also list the top 50 processes that consume the most memory through the following command:

ps auxw|head -1;ps auxw|sort -rn -k4|head -50
Copy after login

Solution process:

Let’s modify the configuration below file to optimize php-fpm to reduce memory usage.

My php-fpm configuration file is in the .../server/php/etc/ directory, enter this directory.

Back up the original configuration file first:

cp php-fpm.conf php-fpm.conf.bak
Copy after login

Note:

After using vim to open the configuration file, press the Esc key, and then enter "/" , then enter "xxx" to search for the string "xxx".

The specific configuration parameters are as follows:

pm.max_children = 100改为:pm.max_children = 25
pm.start_servers = 20改为pm.start_servers = 5
pm.min_spare_servers = 5改为pm.min_spare_servers = 2
pm.max_spare_servers = 35改为pm.max_spare_servers = 10
Copy after login

Restart the server:

reboot
Copy after login

After restarting, you can find that the memory usage is lower than before.

Note:

1. Description of the parameters in php-fpm.conf:

pm.max_children:静态方式下开启的php-fpm进程数量。
pm.start_servers:动态方式下的起始php-fpm进程数量。
pm.min_spare_servers:动态方式下的最小php-fpm进程数。
pm.max_spare_servers:动态方式下的最大php-fpm进程数量。
Copy after login

2. When making the above settings, I will php -The execution mode of -fpm is set to dynamic:

pm = dynamic
Copy after login

3.php-fpm has two execution modes:

One is Static and the other is Dynamic. If set to static, only the pm.max_children parameter will take effect. If set to dynamic, the three parameters pm.start_servers, pm.min_spare_servers and pm.max_spare_servers will take effect. After setting it to dynamic, when php-fpm starts, it will start the corresponding number of processes according to the parameter setting of pm.start_servers. After that, the number of processes of php-fpm will be maintained between the number specified by pm.min_spare_servers and pm.max_spare_servers.

4. How to choose to use the static or dynamic execution mode of php-fpm:

The dynamic php-fpm execution mode allows php-fpm to release redundant processes, thus saving memory resources.

The static php-fpm execution method does not allow php-fpm to release more than processes, which avoids frequently starting or stopping the php-fpm process, thereby reducing the server's response time in some cases.

For more PHP related knowledge, please visit PHP Tutorial!

The above is the detailed content of Solve the problem of excessive server memory resource consumption caused by too many php-fpm processes in CentOS7. 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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 use php-fpm for high-performance tuning How to use php-fpm for high-performance tuning Jul 08, 2023 am 11:30 AM

How to use php-fpm for high-performance tuning PHP is a very popular server-side scripting language that is widely used to develop web applications and dynamic websites. However, as traffic increases, the performance of your PHP application may suffer. In order to solve this problem, we can use php-fpm (FastCGIProcessManager) for high-performance tuning. This article will introduce how to use php-fpm to improve the performance of PHP applications and provide code examples. one,

How to use PHP-FPM optimization to improve the performance of PrestaShop applications How to use PHP-FPM optimization to improve the performance of PrestaShop applications Oct 05, 2023 pm 12:33 PM

How to use PHP-FPM optimization to improve the performance of PrestaShop applications. With the rapid development of the e-commerce industry, PrestaShop has become the e-commerce platform chosen by many merchants. However, as the size of the store increases and the number of visits increases, the PrestaShop application may encounter performance bottlenecks. In order to improve the performance of the PrestaShop application, a common method is to use PHP-FPM to optimize and improve the application's processing capabilities. PHP-FPM (FastCGI

How to improve the performance of your WooCommerce application using PHP-FPM optimization How to improve the performance of your WooCommerce application using PHP-FPM optimization Oct 05, 2023 am 08:24 AM

How to Improve the Performance of WooCommerce Applications Using PHP-FPM Optimization Overview WooCommerce is a very popular e-commerce plugin for creating and managing online stores on WordPress websites. However, as your store grows and traffic increases, WooCommerce apps can become slow and unstable. To solve this problem, we can use PHP-FPM to optimize and improve the performance of WooCommerce applications. What is PHP-FP

Use php-fpm connection pool to improve database access performance Use php-fpm connection pool to improve database access performance Jul 07, 2023 am 09:24 AM

Overview of using php-fpm connection pool to improve database access performance: In web development, database access is one of the most frequent and time-consuming operations. The traditional method is to create a new database connection for each database operation and then close the connection after use. This method will cause frequent establishment and closing of database connections, increasing system overhead. In order to solve this problem, you can use php-fpm connection pool technology to improve database access performance. Principle of connection pool: Connection pool is a caching technology that combines a certain number of databases

How to use PHP-FPM optimization to improve the performance of Phalcon applications How to use PHP-FPM optimization to improve the performance of Phalcon applications Oct 05, 2023 pm 01:54 PM

How to use PHP-FPM to optimize and improve the performance of Phalcon applications. Introduction: Phalcon is a high-performance PHP framework. Combining with PHP-FPM can further improve the performance of applications. This article will introduce how to use PHP-FPM to optimize the performance of Phalcon applications and provide specific code examples. 1. What is PHP-FPMPHP-FPM (PHPFastCGIProcessManager) is a PHP process independent of the web server

Detailed explanation of php-fpm tuning method Detailed explanation of php-fpm tuning method Jul 08, 2023 pm 04:31 PM

PHP-FPM is a commonly used PHP process manager used to provide better PHP performance and stability. However, in a high-load environment, the default configuration of PHP-FPM may not meet the needs, so we need to tune it. This article will introduce the tuning method of PHP-FPM in detail and give some code examples. 1. Increase the number of processes. By default, PHP-FPM only starts a small number of processes to handle requests. In a high-load environment, we can improve the concurrency of PHP-FPM by increasing the number of processes

Use php-fpm process management to achieve load balancing Use php-fpm process management to achieve load balancing Jul 09, 2023 pm 01:07 PM

Using php-fpm process management to achieve load balancing As Internet applications become increasingly complex and the number of users increases, load balancing has become an indispensable technology. The goal of load balancing is to distribute traffic to multiple servers to improve system stability and performance. In PHP applications, php-fpm (PHPFastCGIProcessManager) is a common process management tool that can be used to achieve load balancing and provides flexible configuration options. This article will introduce how to use

PHP-FPM performance improvement strategies and practice guide PHP-FPM performance improvement strategies and practice guide Oct 05, 2023 pm 03:55 PM

Introduction to PHP-FPM Performance Improvement Strategies and Practice Guide: With the rapid development of the Internet and the increasing number of website visits, it is particularly important to improve the performance of PHP applications. PHPFastCGIProcessManager (PHP-FPM) is a commonly used PHP process manager that can improve the performance of PHP applications through a series of strategies and practices. This article will introduce some PHP-FPM performance improvement strategies, combined with specific code examples, to help readers better understand

See all articles