首页 > 解决方案 > Apache 2.4 php 7.2 Apache(php 模块)增加最大连接数以处理 10000

问题描述

我有 apache(2.4) 和 php(7.2) 的项目,其中 apache 使用 mpm_fork 如何增加 apache 中的最大连接数以处理 10,000 个并发连接?我正在使用https://loader.io进行测试,它最多只能处理 5000 个并发连接(在 15 秒内)。

这是我当前的 apache 配置:

DefaultRuntimeDir ${APACHE_RUN_DIR}
Timeout             300
<IfModule prefork.c>
    StartServers            100
    MinSpareServers         100
    MaxSpareServers         100
    ServerLimit             10000
    MaxClients              10000
    MaxRequestWorkers       10000
    MaxRequestsPerChild     4000
</IfModule>
PidFile ${APACHE_PID_FILE}
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>
<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
ServerName localhost

考虑一下,我的硬件没有问题,我检查了我的资源使用情况,我在测试期间从未超过 20% 的 cpu 和内存使用率。

标签: phpapachehigh-traffic

解决方案


我为已经在我的服务器上完美运行的 Apache 找到的最佳调优是这部分:

<IfModule prefork.c>
    StartServers            20
    MinSpareServers         20
    MaxSpareServers         50
    ServerLimit             5000
    MaxRequestWorkers       5000
    MaxRequestsPerChild     10000
</IfModule>

我相信这个配置对高流量服务器有好处。


推荐阅读