gpt4 book ai didi

linux - httpd 的 mpm 配置

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:13 25 4
gpt4 key购买 nike

我在 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 内存吗?

最佳答案

一个标准的 Apache 进程占用大约 12 MB 的 RAM。如果您为 Apache 保留了 30 GB,您将永远无法达到 serverlimit 100 (=100*12MB=1200MB=1,2​​GB)。所以我假设 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 中使用的术语。

此外,您还可以更改以下变量:

#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

为了进一步防止缓慢的 dos 或堆积打开的 session ,您可以使用 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 的原因 --> TOOLS

关于linux - httpd 的 mpm 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43231139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com