Ubuntu – Apache server is very slow taking minutes to respond

apache-2.2Ubuntu

I have Ubuntu 12.04 64-bit and Apache 2.2.22 installed on my machine used for development. Anyway, it seems from one day to the next that it would serve the pages in milliseconds to now 5 minutes 1 second every time. I believe that this is because the timeout value is 300 in the apache.conf. What I don't understand is why it is timing out.

I have xdebug installed but I am not triggering it and it is not on autostart so I really think this would have made no difference and they were working together fine before.

I am a complete noob at Apache and not sure how to start debugging the issue. I have checked the logs but they don't seem to give me anything interesting. The Apache error.log is not changing and only producing a notice log when it boots.

The actual app log is a bit more interesting as in it does update the app-access.log and the app-error.log, however the access log just says the GET requests and the error log is all info. The make no sense to me so here is an example of one from a request.

[Mon Jan 20 12:01:39 2014] [info] [client 127.0.0.1] (32)Broken pipe: core_output_filter: writing data to the network
[Mon Jan 20 12:01:43 2014] [info] [client ::1] Connection to child 6 established (server app:443)
[Mon Jan 20 12:01:43 2014] [info] Seeding PRNG with 656 bytes of entropy
[Mon Jan 20 12:01:43 2014] [info] [client ::1] SSL library error 1 in handshake (server app:443)
[Mon Jan 20 12:01:43 2014] [info] SSL Library Error: 336027900 error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol speaking not SSL to HTTPS port!?
[Mon Jan 20 12:01:43 2014] [info] [client ::1] Connection closed to child 6 with abortive shutdown (server app:443)

The thing is that it only produces a log when the page is served which is minutes later (after the apparent 5 min timeout). It seems that it takes ages for the request to actually hit the app. I am not sure what is the best way to go about finding why this is the case. I have made no changes recently to my configuration so I really don't see why it has suddenly gone awry.

Best Answer

Well if the config didn't change, you have no choice but to limit the timeout to 2 seconds, then you have 3 second load time.. ;) Okey, let's try something helpful..

You say you use it for local development testing?

Can you remember what the very last change was to any of the following:

  • Your web application, any changes between when it was working and when it wasn't?
    • Is there a for .. loop that runs infinitely?
    • Or is your application making a request to a another server that is not responding?
  • Any other logs to check? PHP's error log or any other scripting language's that you may be using.
  • Database settings, table structures? Constraints? Procedures?
    • Are you using a database that has some locks that your application is waiting for?
  • Scripting language settings (PHP, Perl, Python, Ruby which are you running?)
  • Apache settings
    • Modules
    • Virtual Hosts
    • .htaccess files?
  • Any updates to any other services on the server?
  • Any firewall changes?
  • Any updates of database, scripting language or Apache?

Other things to check:

  • If that does not help, you should increase the verbosity of Apache's logging up to debug in steps and see what is going on during the 5 minutes..
  • You may also see which process is using the cpu while the request is running (if any at all), e.g. PHP taking up an entire CPU core? Or maybe mysqld (or any other database daemon)..

[EDIT] See this too: https://web.archive.org/web/20170225085205/http://servertune.com/kbase/?View=entry&EntryID=109