2

I have project with apache(2.4) and php(7.2), which apache uses mpm_fork how can I increase max connections in apache to handle 10,000 cocurrent connections ? I'm testing with https://loader.io , It just can handle max to 5000 concurrent connections ( in 15 s ).

this is my current apache config :

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

consider, there is no problem with my hardware, I checked my resource usage, I never passed 20 % usage of cpu and memory during my tests.

Majid Abdolhosseini
  • 2,191
  • 4
  • 31
  • 59
  • Buy more powerful hardware? Optimise your PHP code? Load balancing? Caching? Use a CDN? .....? – Spudley Nov 09 '18 at 12:33
  • there is no problem with my hardware, I checked my resource usage, I never passed 20 % usage of cpu and memory during my tests. – Majid Abdolhosseini Nov 09 '18 at 12:56
  • So how did you measure that it handled requests up to 5000 at max? What will happen after that 15 seconds? – revo Nov 09 '18 at 13:16
  • requests get timeout – Majid Abdolhosseini Nov 09 '18 at 14:12
  • If your server is going great but your test fails at around 5000, then your test system could be running out of resources. I see 1 problem. `MaxRequestsPerChild` is way too small. This value is the number of requests are processed by a child process before it is killed and a new one is started. So at the numbers you are talking about, they will restart all the time, makes no sense. I have seen 100 000 of even higher. – Nic3500 Nov 09 '18 at 19:51
  • If request timeout, it means a network trouble or apache trouble (combined php as well). Make sure you verify your system for open file descriptors, kernel limits and user limits. If these limits are too low, the system will appear "clean" but still block. – Nic3500 Nov 09 '18 at 19:55

1 Answers1

5

The best tuning I found for Apache which already working on my server perfectly is this part :

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

I belive this config is good for high traffic servers.

Majid Abdolhosseini
  • 2,191
  • 4
  • 31
  • 59