Search code examples
apachelamp

Performance - How To Debug Slow Ubuntu Apache/PHP/MySQL Server


I run an Apache/PHP/MySQL webserver running on Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64) with 4gb of RAM.

Over the last few days, as load on the server has increased (100-200 requests per second), it seems to have stopped serving pages altogether. Here are some performance stats:

  • Incoming network I/O: 2mb/s
  • Outgoing network I/O: 11mb/s
  • Memory (RAM) in use: 1.1gb
  • CPU usage: 2%

Here are the values in mpm_prefork.conf:

<IfModule mpm_prefork_module>
    StartServers              5
    MinSpareServers           5
    MaxSpareServers           50
    MaxRequestWorkers         150
    MaxConnectionsPerChild    5000
</IfModule>

The requests occur on pages which typically have one database query and return data formatted in JSON. It is not graphical/database/resource intensive.

Restarting the webserver will allow it to serve pages for around 1 minute, until load picks up and it returns to a frozen state.

What can I look for or change to resolve this?


Solution

  • You first have to determine if your problem is on the Apache Server, on the PHP code, on the mySQL database queries or even on mySQL database parameters.

    You need to do profiling focused on these components.

    By the CPU and memory usage it does not seen to be a problem with your hardware sizing, but something related to the application configuration or component parametrization.

    I would start by checking how long does the SQL requests are taking. Just google mysql database profiling tools and you are gonna find your way to increase mySQL perfomance if needed.