Apache 每个子进程占用过多内存

Apache 每个子进程占用过多内存

我遇到了以下问题:Apache 每个子进程消耗了太多的内存。

以下评论表明:

  1. cat /etc/redhat-release -- Fedora 版本 8(狼人)

  2. 免费-m:

             total       used       free     shared    buffers     cached
Mem:          3566       3136        429          0        339       1907
-/+ buffers/cache:        889       2676
Swap:         4322          0       4322

我知道您会说没有什么可担心的,因为 swap 没有用,但我认为它现在没有用。

3.httpd -v:

服务器版本:Apache/2.2.14 (Unix)

4.httpd -l:

以模块形式编译:

核心.c

mod_authn_文件

mod_authn_默认.c

mod_authz_主机

mod_authz_组文件

mod_authz_用户配置文件

mod_authz_默认.c

mod_auth_basic.c

mod_include文件

mod_filter.c

mod_log_配置.c

mod_env.c

mod_setenvif配置文件

mod_版本.c

mod_ssl.c

预分叉

http_核心.c

mod_mime.c

mod_status.c

mod_autoindex.c

mod_asis.c

mod_cgi配置文件

mod_negotiation.c

mod_dir.c

mod_actions.c

mod_用户目录

mod_alias 库

mod_rewrite.c

mod_so.c

5.加载的动态模块列表:

加载模块 authz_host_module

模块/mod_authz_host.so 加载模块

include_module 模块/mod_include.so

加载模块 log_config_module

模块/mod_log_config.so 加载模块

设置环境变量

模块/mod_setenvif.so 加载模块

mime_module 模块/mod_mime.so

加载模块自动索引模块

模块/mod_autoindex.so 加载模块

vhost_alias_module 模块/mod_vhost_alias.so LoadModule

谈判模块

模块/mod_negotiation.so 加载模块

dir_module 模块/mod_dir.so

LoadModule 别名_模块

模块/mod_alias.so 加载模块

rewrite_module 模块/mod_rewrite.so

加载模块 proxy_module

模块/mod_proxy.so 加载模块

cgi_module 模块/mod_cgi.so

6.我的 prefrok 指令

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   25
ServerLimit       80
MaxClients        80
MaxRequestsPerChild  4000
</IfModule>

KeepAliveTimeout 6
MaxKeepAliveRequests 100
KeepAlive On

7.top -u apache:ctrl+M

top - 09:19:42 up 2 days, 19 min,  2 users,  load average: 0.85, 0.87, 0.80
Tasks: 113 total,   1 running, 112 sleeping,   0 stopped,   0 zombie
Cpu(s):  7.3%us, 15.7%sy,  0.0%ni, 75.7%id,  0.0%wa,  0.7%hi,  0.7%si,  0.0%st
Mem:   3652120k total,  3149964k used,   502156k free,   348048k buffers
Swap:  4425896k total,        0k used,  4425896k free,  1944952k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
16956 apache    20   0  700m 135m 100m S  0.0  3.8   2:16.78 httpd
16953 apache    20   0  565m 130m  96m S  0.0  3.7   1:57.26 httpd
16957 apache    20   0  587m 129m 102m S  0.0  3.6   1:47.41 httpd
16955 apache    20   0  567m 126m  93m S  0.0  3.6   1:43.60 httpd
17494 apache    20   0  626m 125m  96m S  0.0  3.5   1:58.77 httpd
17515 apache    20   0  540m 120m  88m S  0.0  3.4   1:45.57 httpd
17516 apache    20   0  573m 120m  88m S  0.0  3.4   1:50.51 httpd
16954 apache    20   0  551m 120m  88m S  0.0  3.4   1:52.47 httpd
17493 apache    20   0  586m 120m  94m S  0.0  3.4   1:51.02 httpd
17279 apache    20   0  568m 117m  87m S 16.0  3.3   1:51.87 httpd
17302 apache    20   0  560m 116m  90m S  0.3  3.3   1:59.06 httpd
17495 apache    20   0  551m 116m  89m S  0.0  3.3   1:47.51 httpd
17277 apache    20   0  476m 114m  81m S  0.0  3.2   1:37.14 httpd
30097 apache    20   0  536m 113m  83m S  0.0  3.2   1:47.38 httpd
30112 apache    20   0  530m 112m  81m S  0.0  3.2   1:40.15 httpd
17513 apache    20   0  516m 112m  85m S  0.0  3.1   1:43.92 httpd
16958 apache    20   0  554m 111m  82m S  0.0  3.1   1:44.18 httpd
 1617 apache    20   0  487m 111m  85m S  0.0  3.1   1:31.67 httpd
16952 apache    20   0  461m 107m  75m S  0.0  3.0   1:13.71 httpd
16951 apache    20   0  462m 103m  76m S  0.0  2.9   1:28.05 httpd
17278 apache    20   0  497m 103m  76m S  0.0  2.9   1:31.25 httpd
17403 apache    20   0  537m 102m  79m S  0.0  2.9   1:52.24 httpd
25081 apache    20   0  412m 101m  70m S  0.0  2.8   1:01.74 httpd

我想这就是帮助我解决这个问题所需的所有信息。我认为虚拟内存太大了,同样的资源。内存的消耗一直在增加。也许是内存泄漏,因为我看到编译了太多的静态模块。

有人能帮我解决这个问题吗?提前谢谢您。

8.ldd /usr/sbin/httpd

linux-gate.so.1 =>  (0x0012d000)
libm.so.6 => /lib/libm.so.6 (0x0012e000)
libpcre.so.0 => /lib/libpcre.so.0 (0x00157000)
libselinux.so.1 => /lib/libselinux.so.1 (0x0017f000)
libaprutil-1.so.0 => /usr/lib/libaprutil-1.so.0 (0x0019a000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x001b4000)
libldap-2.3.so.0 => /usr/lib/libldap-2.3.so.0 (0x001e6000)
liblber-2.3.so.0 => /usr/lib/liblber-2.3.so.0 (0x00220000)
libdb-4.6.so => /lib/libdb-4.6.so (0x0022e000)
libexpat.so.1 => /lib/libexpat.so.1 (0x00370000)
libapr-1.so.0 => /usr/lib/libapr-1.so.0 (0x00391000)
libpthread.so.0 => /lib/libpthread.so.0 (0x003b9000)
libdl.so.2 => /lib/libdl.so.2 (0x003d2000)
libc.so.6 => /lib/libc.so.6 (0x003d7000)
/lib/ld-linux.so.2 (0x00110000)
libuuid.so.1 => /lib/libuuid.so.1 (0x00530000)
libresolv.so.2 => /lib/libresolv.so.2 (0x00534000)
libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0x00548000)
libssl.so.6 => /lib/libssl.so.6 (0x00561000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x005a6000)
libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x006d9000)
libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x00707000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x0079a000)
libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x0079d000)
libz.so.1 => /lib/libz.so.1 (0x007c3000)
libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0x007d6000)
libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x007df000)

目前我无法重新启动 Apache。我在一家公司工作,现在正值高峰期。我会在下午 5 点左右重新启动。

当前顶部 -u apache:shift + M

top - 12:31:33 up 2 days,  3:30,  1 user,  load average: 0.73, 0.80, 0.79
Tasks: 114 total,   1 running, 113 sleeping,   0 stopped,   0 zombie
Cpu(s):  3.3%us,  4.7%sy,  0.0%ni, 90.0%id,  1.3%wa,  0.3%hi,  0.3%si,  0.0%st
Mem:   3652120k total,  3169720k used,   482400k free,   353372k buffers
Swap:  4425896k total,        0k used,  4425896k free,  1978688k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
16957 apache    20   0  708m 145m 117m S  0.0  4.1   2:11.32 httpd
16956 apache    20   0  754m 142m 107m S  0.0  4.0   2:33.94 httpd
16955 apache    20   0  641m 136m 103m S  5.3  3.8   1:58.37 httpd
17515 apache    20   0  624m 131m  99m S  0.0  3.7   2:03.90 httpd
16954 apache    20   0  627m 130m  98m S  0.0  3.6   2:13.87 httpd
17302 apache    20   0  625m 124m  97m S  0.0  3.5   2:10.80 httpd
17403 apache    20   0  624m 114m  91m S  0.0  3.2   2:08.85 httpd
16952 apache    20   0  502m 114m  81m S  0.0  3.2   1:23.78 httpd
16186 apache    20   0  138m  61m  35m S  0.0  1.7   0:15.54 httpd
16169 apache    20   0  111m  49m  17m S  0.0  1.4   0:06.00 httpd
16190 apache    20   0  126m  48m  24m S  0.0  1.4   0:11.44 httpd
16191 apache    20   0  109m  48m  19m S  0.0  1.4   0:04.62 httpd
16163 apache    20   0  114m  48m  21m S  0.0  1.4   0:09.60 httpd
16183 apache    20   0  127m  48m  23m S  0.0  1.3   0:11.23 httpd
16189 apache    20   0  109m  47m  17m S  0.0  1.3   0:04.55 httpd
16201 apache    20   0  106m  47m  17m S  0.0  1.3   0:03.90 httpd
16193 apache    20   0  103m  46m  20m S  0.0  1.3   0:10.76 httpd
16188 apache    20   0  107m  45m  18m S  0.0  1.3   0:04.85 httpd
16168 apache    20   0  103m  44m  17m S  0.0  1.2   0:05.61 httpd
16187 apache    20   0  118m  41m  21m S  0.0  1.2   0:08.50 httpd
16184 apache    20   0  111m  41m  19m S  0.0  1.2   0:09.28 httpd
16206 apache    20   0  110m  41m  20m S  0.0  1.2   0:11.69 httpd
16199 apache    20   0  108m  40m  17m S  0.0  1.1   0:07.76 httpd
16166 apache    20   0  104m  37m  18m S  0.0  1.0   0:04.31 httpd
16185 apache    20   0 99.3m  36m  16m S  0.0  1.0   0:04.16 httpd

如您所见,内存使用量从例如 res(135 到 145)m 不断增长,并且会一直增长直到内存耗尽。您确定我设置了此选项吗:

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   25
ServerLimit       80
MaxClients        80
MaxRequestsPerChild  4000
</IfModule>

KeepAliveTimeout 6
MaxKeepAliveRequests 100
KeepAlive On

是正确的吗?也许我应该减少一些?

另一个困扰我的问题是:我将静态模块mod_negotiation.c编译到 apache 中,并将相同的模块加载为动态模块。我加载了重复的模块,这正常吗?但是当我想从 httpd.conf 中删除动态模块 (mod_negotiation.c) 然后重新启动 apache 时,会出现错误。现在我无法显示此错误消息,因为我无法重新启动 apache :(


再次问好:)这是重新启动 Apache 之后的内存使用情况:

top - 16:19:12 up 2 days,  7:18,  3 users,  load average: 1.08, 0.91, 0.91
Tasks: 109 total,   2 running, 107 sleeping,   0 stopped,   0 zombie
Cpu(s): 17.0%us, 25.7%sy, 51.0%ni,  4.7%id,  0.0%wa,  0.3%hi,  1.3%si,  0.0%st
Mem:   3652120k total,  2762516k used,   889604k free,   361552k buffers
Swap:  4425896k total,        0k used,  4425896k free,  2020980k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
13569 apache    20   0 93416  43m  15m S  0.0  1.2   0:02.55 httpd
13575 apache    20   0 98356  38m  16m S 32.3  1.1   0:02.55 httpd
13571 apache    20   0 86808  33m  12m S  0.0  0.9   0:02.60 httpd
13568 apache    20   0 86760  33m  12m S  0.0  0.9   0:00.81 httpd
13570 apache    20   0 83480  33m  12m S  0.0  0.9   0:00.51 httpd
13572 apache    20   0 63520 5916 1548 S  0.0  0.2   0:00.02 httpd
13573 apache    20   0 63520 5916 1548 S  0.0  0.2   0:00.02 httpd
13574 apache    20   0 63520 5916 1548 S  0.0  0.2   0:00.02 httpd
13761 apache    20   0 63388 5128  860 S  0.0  0.1   0:00.01 httpd
13762 apache    20   0 63388 5128  860 S  0.0  0.1   0:00.01 httpd
13763 apache    20   0 63388 5128  860 S  0.0  0.1   0:00.00 httpd

我将尝试将 apache 从源代码编译到最新版本。谢谢大家的帮助。

答案1

来自 Apache2.2.15 变更日志2.2.15 中修复了内存泄漏问题,但如果您的 top 输出是在 apache 启动后,那么在我看来,它确实非常大。
您尝试过 worker 配置吗?
您可以在 httpd 二进制文件上添加 ldd 工具的输出吗?

答案2

如果我是你,我就不会担心。free 表示你使用了 800MB,还有大约 2GB 的可用空间。Apache 不是轻量级服务器,而且你有很多模块。

相关内容