我们有Apache运行的工人MPM和MaxClients设置为6,但是当我打开顶部,我可以看到超过6个Apache进程运行。 13下面的屏幕转储中可见。 有人可以解释这个吗? 还有一个来自/ server-status /的屏幕转储,大约在同一时间。 在我们正常的加载下,似乎一次只能处理2-6个请求,所以我期望看到许多apache2进程在最前面运行。 我可以协调这一点的唯一方法是假设在最大负载下,有3个服务器运行(ServerLimit 3,3 apache2进程),每个都有2个线程(3×2 = 6个apache2进程),但即使这样也会导致9个apache进程最多运行。
Apache本质上是逃避,从不释放内存。 我们每秒提供大约5-6个请求,使用/ server-status /进行监视,所以我认为将MaxRequestsPerChild设置为1000(我们已经使其低至500)会导致进程回收并释放内存,但是这并不似乎发生。 我们通过New Relic来监视Apache进程内存。 当我们重新启动Apache时,下面的configuration会消耗大约550M的内存。 每个进程最终都会膨胀到VIRT:300m RES:80m,我们似乎无法控制正在运行的进程数量,所以Apache在12-14小时内从550M-5G上升,并将我们抹去。
我已经检查了/conf.d/目录,以确保我们不覆盖我们的apacheconfiguration中的任何设置。 有没有人有任何build议获得Apache的控制权? 我知道我们有一个运行mod_wsgi的胖python应用程序,可能有内存泄漏,当然可以优化,但我只是想控制产生的apache进程的数量。
Apacheconfiguration:
### Section 1: Global Environment # # The directives in this section affect the overall operation of Apache, # such as the number of concurrent requests it can handle or where it # can find its configuration files. # ServerRoot "/etc/apache2" ServerName localhost LockFile ${APACHE_LOCK_DIR}/accept.lock PidFile ${APACHE_PID_FILE} Timeout 120 KeepAlive Off ExtendedStatus On # worker MPM # StartServers: initial number of server processes to start # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadLimit: ThreadsPerChild can be changed to this maximum value during a # graceful restart. ThreadLimit can only be changed by stopping # and starting Apache. # ThreadsPerChild: constant number of worker threads in each server process # MaxClients: maximum number of simultaneous client connections # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_worker_module> StartServers 1 ThreadsPerChild 2 MinSpareThreads 1 MaxSpareThreads 2 MaxClients 6 ServerLimit 3 MaxRequestsPerChild 1000 </IfModule> # These need to be set in /etc/apache2/envvars User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} AccessFileName .htaccess <Files ~ "^\.ht"> Order allow,deny Deny from all Satisfy all </Files> DefaultType None HostnameLookups Off ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn LogFormat "%v:%p %a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%a %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent # Include module configuration: Include mods-enabled/*.load Include mods-enabled/*.conf # Include ports listing Include ports.conf # Include generic snippets of statements Include conf.d/
最佳:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 24775 www-data 20 0 282m 68m 5160 S 104 0.8 3:04.67 apache2 24782 www-data 20 0 283m 66m 5376 S 57 0.8 3:24.31 apache2 24780 www-data 20 0 280m 65m 4976 S 55 0.8 3:20.74 apache2 24778 www-data 20 0 289m 72m 5540 S 29 0.9 3:09.55 apache2 24773 www-data 20 0 278m 64m 5116 S 26 0.8 2:55.66 apache2 24777 www-data 20 0 282m 65m 4664 S 20 0.8 3:08.39 apache2 13433 memcache 20 0 642m 597m 876 S 16 7.4 11:46.62 memcached 24774 www-data 20 0 288m 71m 4672 S 15 0.9 3:12.58 apache2 24781 www-data 20 0 283m 66m 5160 S 11 0.8 3:16.01 apache2 24779 www-data 20 0 281m 64m 4676 S 8 0.8 3:11.44 apache2 24776 www-data 20 0 284m 74m 4660 S 8 0.9 2:56.38 apache2 27105 www-data 20 0 49520 6180 2636 S 2 0.1 0:00.05 apache2 27100 www-data 20 0 49432 6084 2628 S 1 0.1 0:00.06 apache2 9 root 20 0 0 0 0 S 1 0.0 62:05.25 rcu_sched 27007 www-data 20 0 49568 6292 2684 S 1 0.1 0:00.60 apache2 1 root 20 0 3496 872 428 S 0 0.0 0:04.61 init 2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0 0.0 0
/服务器状态/
Apache Server Status for www.mysite.com Server Version: Apache/2.2.22 (Ubuntu) mod_ssl/2.2.22 OpenSSL/1.0.1 mod_wsgi/3.3 Python/2.7.3 Server Built: Feb 13 2012 01:37:45 Current Time: Tuesday, 18-Feb-2014 10:53:01 EST Restart Time: Tuesday, 18-Feb-2014 10:25:32 EST Parent Server Generation: 0 Server uptime: 27 minutes 28 seconds Total accesses: 8248 - Total Traffic: 126.6 MB CPU Usage: u.36 s.15 cu0 cs0 - .0309% CPU load 5 requests/sec - 78.7 kB/second - 15.7 kB/request 2 requests currently being processed, 0 idle workers ................................................................ ................................................................ WW.............................................................. Scoreboard Key: "_" Waiting for Connection, "S" Starting up, "R" Reading Request, "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup, "C" Closing connection, "L" Logging, "G" Gracefully finishing, "I" Idle cleanup of worker, "." Open slot with no current process Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request 0-0 - 0/0/1569 . 0.02 0 37 0.0 0.00 25.22 67.217.125.252 www.mysite.com GET /imgname.jpg HTTP/1.0 0-0 - 0/0/1502 . 0.03 0 786 0.0 0.00 22.47 65.55.52.119 www.mysite.com GET / HTTP/1.0 1-0 - 0/0/1629 . 0.04 13 260 0.0 0.00 24.85 70.208.67.110 www.mysite.com GET /article/s 1-0 - 0/0/1416 . 0.04 13 469 0.0 0.00 21.42 98.109.237.89 www.mysite.com GET / HTTP/1.0 2-0 27863 0/54/1021 W 0.44 0 0 0.0 0.69 15.95 66.151.5.10 www.mysite.com GET /storm-h 2-0 27863 0/50/1111 W 0.44 0 0 0.0 0.61 16.73 108.88.80.66 www.mysite.com GET /server-status/ HTTP/1.0
UPDATE
这个问题有多个步骤解决。
1)确定mod_wsgi进程被顶部报告为apache2。 要解决这个问题,请在您的WSGIDaemonProcessconfiguration中添加display-name = my-mod-wsgi-app参数。
2)我们发现我们的python / Django应用程序有一些可怕的部分导致mod_wsgi进程膨胀到600M。 运行其中的5个会消耗我们的VPS的内存3G,并使其非常难过。
3)我们在WSGIDaemonProcessconfiguration文件中添加了inactivity-timeout = 300和maximum-requests = 200,并且mod_wsgi在一个进程没有被使用或者超过500个请求时很好地重新启动,这让我们的超重,sl散的Django应用程序能够平稳地运行。
感谢格雷厄姆让我开始朝这个方向发展。 您可以阅读我在mod_wsgi Google群组上通过解决这个问题的方式。 https://groups.google.com/forum/#!topic/modwsgi/wYScZlqgjgA
stream程的细分是:
如果使用WSGIDaemonProcess的display-name选项,那么一些工具(如BSD派生的“ps”命令和“htop”)将显示您指定的名称而不是“apache2”。 这样你就可以区分哪些是运行你的web应用程序的mod_wsgi守护进程。
推断更多,你需要显示你正在使用的mod_wsgiconfiguration是什么。 现在虽然看起来你的configuration很差,即使MPM设置运行的线程数量太less,而且在使用Apache worker MPM的过程中运行起来也不是很合理。
无论哪种方式,StackOverflow不是一个论坛,因此是一个非常糟糕的地方尝试,并进行长时间的讨论,以帮助理清你的configuration。 你最好使用mod_wsgi邮件列表。
我也build议你看/读: