大网数据广告活动
服务器运维问答

Why is Apache spawning so many processes?

· 52CE 我爱测

I have a Wordpress blog with one post. I wanted to self-host for the experience and "fun" of it. I rarely get any viewers at all because I am just setting up. I am on an Amazon EC2-micro Arch-Linux instance using Apache 2.4.23 an…

问题原文

原帖链接 · Mike Flynn · CC BY-SA 3.0

I have a Wordpress blog with one post. I wanted to self-host for the experience and "fun" of it. I rarely get any viewers at all because I am just setting up. I am on an Amazon EC2-micro Arch-Linux instance using Apache 2.4.23 and MySQL 5.5.52 to run Wordpress. I have 1 GB of RAM.

I did not think that this would be a resource heavy application, but every time I try to run Wordpress, after a couple days the server always crashes. This is due to Apache spawning 100s of processes and not killing them. Shouldn't these go away after a while?

I have spent quite a bit of time now googling the problem. I have set up 2 GB of swap trying to fix it. The processes overflow that too. I have added maxClients 40 to my httpd.conf and that seemed to work for a while, but after about 2 weeks Apache crashed again. I have tried other configurations in httpd.conf but they would cause Apache to crash even quicker. I have a block that currently looks like this (after several tries):

# StartServers 3
# MinSpareServers 2
# MaxSpareServers 5
# ServerLimit 10
 maxClients 40
# MaxRequestsPerChild 100
# KeepAliveTimeout 2

Could anyone experienced with this specific problem give me some advice? I'm just trying to host a simple WordPress blog. If it helps, here is my httpd -V

[ec2-user~]$ httpd -V
Server version: Apache/2.4.23 (Amazon)
Server built:   Jul 29 2016 21:42:17
Server's Module Magic Number: 20120211:61
Server loaded:  APR 1.5.1, APR-UTIL 1.4.1
Compiled using: APR 1.5.1, APR-UTIL 1.4.1
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/var/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Edit: Also the fact that these processes are in uninterruptible sleep (IO, Status = D) is problematic!

社区高分解答

原帖链接 · Daniel Ferradal · CC BY-SA 3.0

Shamely, most hosting solutions out there people use, decide to parse php content through Apache with mod_php.

Your PHP installation by default will surely not be thread-safe, this effectively forces Apache to use a non-threading mpm (multi-process module).

Your Apache installation uses prefork (as you can see in the apachectl -V output). This mpm spawns a process per request. So if you are under a bit of load and nowadays knowing how many concurrent requests some browsers send, that list of process is quite usual.

All this make apache crawl and suffer from the load your php scripts cause, making Apache look as it is not performing well, when it is all due to php parsing and unperformant php scripts.

Now, what should you do to avoid this?

Relief Apache from the burden of mod_php, move your php parsing to php-fpm, that will allow you to use Apache HTTPD's "event" mpm, that would even allow you to have 1 process with a thousand threads if you want, and not only that, it is quite more responsive to load spikes and will be as cool and fast as any other http server out there. And most importantly, Apache processes won't be stuck in the hundreds.

You can find some tips on how to configure Apache for this at: Apache Official Wiki PHP entry and mod_proxy_fcgi

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。