简体   繁体   English

异常的 PHP 内存消耗

[英]Unusual PHP Memory Consumption

I have 3 Apache/PHP7 servers running behind a load balancer.我有 3 个 Apache/PHP7 服务器在负载平衡器后面运行。 2 of the 3 servers have been running without issue for several years. 3 台服务器中的 2 台多年来一直没有问题。 The third server (the newest server), however, has a PHP memory consumption issue.但是,第三台服务器(最新的服务器)存在 PHP 内存消耗问题。

While monitoring the servers in real time, I have noticed that the same call (example: /user/login) will require 10x more memory for the 3rd server than the other 2. Example: 18%MEM vs 1.2%MEM在实时监控服务器时,我注意到相同的调用(例如:/user/login)将需要比其他 2 个服务器多 10 倍的内存。例如:18%MEM vs 1.2%MEM

All 3 servers are currently built and managed by ansible, so all 3 configurations should be exactly the same.所有 3 个服务器目前都由 ansible 构建和管理,因此所有 3 个配置应该完全相同。 However, the 2 servers that work as expected, existed before I started using ansible, so its conceivable that there is a config (or configs) set on those servers that is not managed by ansible.但是,在我开始使用 ansible 之前,按预期工作的 2 个服务器已经存在,因此可以想象,在那些不受 ansible 管理的服务器上设置了一个配置(或多个配置)。

All 3 servers run the exact same code base.所有 3 个服务器都运行完全相同的代码库。 All 3 servers are currently running in production.所有 3 个服务器目前都在生产中运行。

The 3rd server has been rebuilt (completely new VM) several times, but always has the same exact issue as before.第三台服务器已重建(全新的虚拟机)多次,但始终存在与以前完全相同的问题。

I have run out of ideas and I would appreciate any help.我的想法已经用完了,我将不胜感激。

Note: I have tried memory tracing tools, but I have had a hard time getting them up and running in production as they are relatively invasive.注意:我尝试过内存跟踪工具,但我很难在生产中启动和运行它们,因为它们相对具有侵入性。

so it's conceivable that there is a config (or configs) set on those servers that is not managed by ansible.因此可以想象,在那些不受 ansible 管理的服务器上设置了一个配置(或多个配置)。

Start from there.从那里开始。

Gather information about:收集有关以下信息:

  • PHP version PHP版本
    • and configuration和配置
  • Linux kernel Linux内核
    • and configuration (eg swappiness)和配置(例如swappiness)
  • libc version库版本
  • Web server version网络服务器版本
    • and configuration和配置

Assuming the three servers have the same amount of memory and the same processes running, any difference can only stem from those parameters.假设三台服务器具有相同的内存量和相同的进程运行,任何差异只能源于这些参数。

You can also try executing a sample command line script to see whether the memory allocation anomaly appears there too.您还可以尝试执行示例命令行脚本,以查看内存分配异常是否也出现在那里。 Whatever it happens, you learn something;无论发生什么,你都会学到一些东西; and if it appears in the script too, it will be easier to run a single instance of the PHP binary through strace or Valgrind just the once.如果它也出现在脚本中,那么通过 strace 或 Valgrind 一次运行 PHP 二进制文件的单个实例会更容易。

It appears the issue was from the php configuration in the 3rd server.看来问题出在第三台服务器中的 php 配置中。 Apparently the 3rd server was configured to use the MPM Event module while the other 2 servers were configured to use MPM Prefork.显然,第三台服务器被配置为使用 MPM 事件模块,而其他 2 台服务器被配置为使用 MPM Prefork。 When I changed the 3rd server to use MPM Prefork, I saw the memory consumption go back down to the level of the other 2.当我将第 3 个服务器更改为使用 MPM Prefork 时,我看到内存消耗又回到了其他 2 个的水平。

I plan to look into the issue further and figure out why the other MPM module had such unusual memory consumption.我计划进一步研究这个问题,并找出为什么另一个 MPM 模块有如此不寻常的内存消耗。

Note, mpm configuration is found here: /etc/httpd/conf.modules.d/00-mpm.conf注意,mpm 配置可以在这里找到:/etc/httpd/conf.modules.d/00-mpm.conf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM