首页 > 解决方案 > Apache 应用程序负载均衡器的高内存使用率

问题描述

我们有一个 ec2 实例 4vcpu 和 16gb 的 ram,它在 aws ELB(应用程序负载均衡器)后面运行带有 mpm 事件的 Apache 服务器。该服务器仅提供我们其他应用程序请求的图像,尽管对于大多数应用程序,我们使用云端进行缓存,但一个应用程序直接在服务器上发送请求。现在 Apache 内存使用量每天都达到 70%,但它并没有下降,我们每次都必须重新启动服务器。较早的旧 Apache 2.2 版本和没有负载平衡器的 worker mpm 我们没有遇到这个问题。我为 MPM EVENT 和 Apache 尝试了不同的配置,但它不起作用。这是apache2.conf

Timeout 120   # also tried the timeout with 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 45 # varies this setting from 1 seconds to 300

这是负载均衡器设置

Mpm 事件

<IfModule mpm_event_module>
    StartServers            2 
    MinSpareThreads         50 
    MaxSpareThreads         75 
    ThreadLimit                      64
    #ServerLimit               400
    ThreadsPerChild          25
    MaxRequestWorkers        400
    MaxConnectionsPerChild   10000
  1. 当我将 MaxRequestWorkers 更改为 150 且 MaxConnectionsPerChild 为 0 并且 ram 使用率达到 47% 时,系统健康检查失败并且自动缩放组启动了新实例。当这个实例使用 8GB Ram 时,似乎已经达到了工人限制。
  2. 我们的其他服务器仅使用简单的 django 站点和 django rest frame api 运行,在安装时配置的 MPM 和 apache 的默认值下工作正常。
  3. 我也尝试过 KeepAliveTimeout 也等于 2、3 和 5 秒的配置,但它不起作用。
  4. 我也按照这个链接输入链接描述在这里它工作得更好,但内存使用量并没有下降。

这是最近的错误日志

[Fri Dec 04 07:45:21.963290 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:22.964362 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:23.965432 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:24.966485 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:25.967281 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:26.968328 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:27.969392 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:28.970449 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:29.971505 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:30.972548 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:31.973593 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:32.974644 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:33.975697 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:34.976753 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.
[Fri Dec 04 07:45:35.977818 2020] [mpm_event:error] [pid 5232:tid 139782245895104] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit.

有时错误日志有这个问题似乎子进程没有被 apache 预先杀死

[Mon Dec 07 07:04:22.142767 2020] [core:warn] [pid 1836:tid 139752646228928] AH00045: child process 2807 still did not exit, sending a SIGTERM
[Mon Dec 07 07:04:24.144831 2020] [core:warn] [pid 1836:tid 139752646228928] AH00045: child process 1847 still did not exit, sending a SIGTERM
[Mon Dec 07 07:04:24.144875 2020] [core:warn] [pid 1836:tid 139752646228928] AH00045: child process 2807 still did not exit, sending a SIGTERM
[Mon Dec 07 07:04:26.146928 2020] [core:warn] [pid 1836:tid 139752646228928] AH00045: child process 1847 still did not exit, sending a SIGTERM
[Mon Dec 07 07:04:26.146967 2020] [core:warn] [pid 1836:tid 139752646228928] AH00045: child process 2807 still did not exit, sending a SIGTERM
[Mon Dec 07 07:04:28.149026 2020] [core:error] [pid 1836:tid 139752646228928] AH00046: child process 1847 still did not exit, sending a SIGKILL
[Mon Dec 07 07:04:28.149092 2020] [core:error] [pid 1836:tid 139752646228928] AH00046: child process 2807 still did not exit, sending a SIGKILL

顶部命令结果

3296 www-data  20   0 3300484 469824  58268 S   0.0  2.9   0:46.46 apache2                                               
 2544 www-data  20   0 3359744 453868  58292 S   0.0  2.8   1:24.53 apache2                                               
 1708 www-data  20   0 3357172 453524  58208 S   0.0  2.8   1:02.85 apache2                                               
  569 www-data  20   0 3290880 444320  57644 S   0.0  2.8   0:37.53 apache2                                               
 3655 www-data  20   0 3346908 440596  58116 S   0.0  2.7   1:03.54 apache2                                               
 2369 www-data  20   0 3290136 428708  58236 S   0.0  2.7   0:35.74 apache2                                               
 3589 www-data  20   0 3291032 382260  58296 S   0.0  2.4   0:50.07 apache2                                               
 4298 www-data  20   0 3151764 372304  59160 S   0.0  2.3   0:18.95 apache2                                               
 4523 www-data  20   0 3140640 310656  58032 S   0.0  1.9   0:07.58 apache2                                               
 4623 www-data  20   0 3139988 242640  57332 S   3.0  1.5   0:03.51 apache2

导致高内存的配置有什么问题?

标签: apacheubuntuamazon-ec2mod-wsgi

解决方案


推荐阅读