【问题标题】:mpm configuration for httpdhttpd的mpm配置
【发布时间】:2017-04-05 12:24:50
【问题描述】:

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

【问题讨论】:

    标签: linux apache amazon-ec2 worker


    【解决方案1】:

    一个标准的 Apache 进程占用大约 12 MB 的 RAM。如果您为 Apache 保留了 30 GB,则服务器限制为 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 更改为MaxClientsMaxRequestWorkers 更改为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>
    

    如果这还不足以解决您的 RAM 问题(如果它们确实是由 Apache 引起的),请相应地使用服务器操作系统的工具来找出占用所有 RAM 的原因 --> TOOLS

    【讨论】:

    • 感谢清晰详细的解释。我刚回来工作。让我试试您的解决方案,并尽快回复您。谢谢鱼。
    猜你喜欢
    • 1970-01-01
    • 2021-06-08
    • 2016-08-08
    • 2014-05-04
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    相关资源
    最近更新 更多