0

I've got multiple virtual hosts on my Ubuntu server. I am running Apache 2.4 & mod_php. At the moment, one website is receiving a lot of traffic - and it is taking time to respond (6+ seconds at times). However - the other websites on this server are all responding instantly. The server isn't under heavy load:

I've got 16 CPUs and the load is currently: 2.27 I'm nowhere near reaching the max memory as there is 48GB and I'm only using around 10GB.

My Virtual Host config file for the site in question is pretty straight forward:

<VirtualHost 0.0.0.0:8080>
        ServerName MySite.com
        ServerAlias *.MySite.com
        ServerAdmin test@test.com
        DocumentRoot /var/www/html/MySite.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

Note that I am using Varnish - which explains the port 8080.

Latest mod_status output for the server:

Server uptime: 1 hour 49 minutes 21 seconds
Server load: 2.70 2.69 2.63
Total accesses: 943706 - Total Traffic: 17.8 GB
CPU Usage: u717.5 s40.96 cu0 cs0 - 11.6% CPU load
144 requests/sec - 2.8 MB/second - 19.8 kB/request
91 requests currently being processed, 24 idle workers

Because this particular site utilises sessions and varnish isn't of any real use to it, I use the following in my default.vcl file to "bypass" varnish altogether:

if (req.http.host ~ "(www)?(mysite).com") {
    set req.http.connection = "close";
    return (pipe);
}

My mpm_prefork.conf file, which applies to all sites on the server:

<IfModule mpm_prefork_module>
        ServerLimit              4000
        StartServers              2
        MinSpareServers           2
        MaxSpareServers          5
        MaxRequestWorkers        4000
        MaxConnectionsPerChild   0
</IfModule>

Screenshot of current top: Image

Any ideas why this might be happening?

I switched to PHP-FPM using the following mpm_worker settings:

<IfModule mpm_worker_module>
    ServerLimit             250
    StartServers             10
    MinSpareThreads          75
    MaxSpareThreads         250 
    ThreadLimit              64
    ThreadsPerChild          32
    MaxClients             8000
    MaxRequestsPerChild   10000
</IfModule>

Site is still taking a while to load - whereas other sites are responding instantly. Top results while using PHP-FPM:

FPM top

My /etc/php5/fpm/pool.d/www.conf settings:

pm = static
pm.max_children = 1200
pm.start_servers = 16
pm.min_spare_servers = 1
pm.max_spare_servers = 36
pm.max_requests = 800
Wayne
  • 73
  • 1
  • 11

1 Answers1

0

mod_php's only running your application in one thread, as that's all it can do - the application's only able to run on one of those 16 CPU cores (confirm in top, one process is probably pegged at 100% of one core)

You'll need to use a different method than mod_php - see here.

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
  • I've added a screenshot of my current top results to the original question. I don't see anything at 100%. You're saying that mod_php will only use 1 of the 16 CPUs regardless of its config? – Wayne Mar 21 '17 at 21:44
  • I switched to FPM (see original question) and there doesn't seem to be that much improvement - even though the other sites are responding instantly. – Wayne Mar 21 '17 at 22:04