我在EC2中运行了一个包含5个httpd服务器(Centos 7)的网站,类型为m3.2xlarge。 服务器配置了负载均衡器。 在所有情况下,服务器内存逐渐增加。
例如:
重启httpd服务后几秒内的内存使用情况:
[centos@ip-10-0-1-77 ~]$ while sleep 1; do free -m; done
total used free shared buff/cache available
Mem: 29741 2700 26732 36 307 26728
Swap: 0 0 0
total used free shared buff/cache available
Mem: 29741 2781 26651 36 307 26647
Swap: 0 0 0
total used free shared buff/cache available
Mem: 29741 2820 26613 36 307 26609
Swap: 0 0 0
[centos@ip-10-0-1-77 ~]$
.
.
.
这是我在一小时后看到的:
[centos@ip-10-0-1-77 ~]$ free -m
total used free shared buff/cache available
Mem: 29741 29092 363 41 284 346
Swap: 0 0 0
如上所述它会在一小时内耗尽所有内存(30GB)。
为了避免这种情况,我开始使用worker mpm配置。
以下配置是我在/etc/httpd/httpd.conf底部添加的内容。
<IfModule mpm_worker_module>
MaxRequestWorkers 2500
MaxSpareThreads 250
MinSpareThreads 75
ServerLimit 100
StartServers 3
ThreadsPerChild 25
</IfModule>
有人可以帮助并建议我在所有情况下正确使用RAM内存的正确配置吗?
答案 0 :(得分:0)
标准Apache进程占用大约12 MB的RAM。如果您为Apache保留了30 GB,则永远不会达到服务器限制为100(= 100 * 12MB = 1200MB = 1,2GB)。所以我认为Apache没有占用所有内存。
是否涉及应用程序或数据库?那些可以占用更多的RAM。
对于你的servertuning.conf
(或httpd.conf,因为你把它放在那里):
<IfModule mpm_worker_module>
#max amount of requests one worker handles before it's forced to close, 2,5k seems almost a little low
MaxRequestsperChild 2500
#maximum number of worker threads which are kept spare
#250 seems quite high, but really depends on the traffic you are experiencing, we normally don't use more than 50-75
MaxSpareThreads 250
#minimum number of worker threads which are kept spare
#really high, only useful if you often experience higher bursts of traffic
#otherwise you should be fine with 15-30, maybe 50 if you experience higher fluctuation -> bigger bursts of requests
MinSpareThreads 75
#upper limit on the configurable number of threads per child process
#you have to increase this if you want more than 64 ThreadsPerChild
ThreadLimit 64
#maximum number of simultaneous client connections
#that is really low! --> increase that, definitely! We run on 1000, so about 12GB max
MaxClients 100
#initial number of server processes to start
#3 is really low, if you expected your server to be flodded with requests the second you start it
#maybe turn it up a little to around 20 or even 50 if you receive lots of traffic right after a restart
StartServers 3
#number of worker threads created by each child proces
#25 threads per worker is not tooo much, but at some point the administration of xx threads gets more expensive than creating new ones
#would suggest to leave it at 25 or turn it up to around 40
ThreadsPerChild 25
</IfModule>
请注意,我已将ServerLimit
更改为MaxClients
而将MaxRequestWorkers
更改为MaxRequestsPerChild
,因为据我所知,这些是mpm-worker
中使用的术语。< / p>
此外,您可以更改以下变量:
#KeepAlive: Whether or not to allow persistent connections (more than
#one request per connection). Set to "Off" to deactivate.
#if it's on, leave it there
KeepAlive On
#MaxKeepAliveRequests: The maximum number of requests to allow
#during a persistent connection. Set to 0 to allow an unlimited amount.
#We recommend you leave this number high, for maximum performance.
#default=100, but you can turn that up if your sites contain a lot of item (img, css, ...)
#we are using about 20*<average object-count per site> = 600
MaxKeepAliveRequests 600
#KeepAliveTimeout: Number of seconds to wait for the next request from the
#same client on the same connection.
#would recommend to decrease that, otherwise you could become a victim of slow-dos attacks
#default is 15, we are running just fine on 5
KeepAliveTimeout 5
为了进一步防止开放会话的慢速或堆积,您可以使用mod_reqtimeout
:
<IfModule mod_reqtimeout.c>
# allow 10s timeout for the headers and allow 1s more until 20s upon receipt of 1000 bytes.
# almost the same with the body, except that it is tricky to
# limit the request timeout within the body at all - it may take time to generate the body.
# below are the default values
#RequestReadTimeout header=10-20,MinRate=1000 body=20,MinRate=1000
# and this is how I'd set them with today's internet speed
# deduct the according numbers from explanation above...
RequestReadTimeout header=2-5,MinRate=100000 body=5-10,MinRate=1000000
</IfModule>
如果这还不足以帮助解决你的RAM问题(如果它们确实是由Apache造成的),请相应地使用服务器操作系统的工具来找出占用所有RAM的内容 - &gt; TOOLS