我在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和上面一样,它在一小时内消耗了所有内存(30 an )。
为了避免这种情况,我开始使用worker mpm配置。
下面的配置是我在/etc/httpd/httpd.conf底部添加的。
<IfModule mpm_worker_module>
MaxRequestWorkers 2500
MaxSpareThreads 250
MinSpareThreads 75
ServerLimit 100
StartServers 3
ThreadsPerChild 25
</IfModule>有人能帮助并建议我在所有实例中正确地使用RAM内存的配置吗?
发布于 2017-04-05 16:26:00
一个标准的Apache进程占用大约12 MB的RAM。如果您为Apache预留了30 GB,那么服务器限制为100 (=100*12MB=1200MB=1,2GB)就永远无法达到。所以我假设Apache没有占用所有的内存。
是否有涉及到的应用程序或DB?它们可以占用更大的内存。
对于您的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中使用的术语。
此外,还可以更改以下变量:
#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>如果这还不足以帮助解决内存问题(如果这些问题确实是由Apache引起的),那么就使用服务器操作系统的工具来找出占用所有RAM -> 工具的原因。
https://stackoverflow.com/questions/43231139
复制相似问题