First of all, I am in no way a professional running a server for about two years from home, so keep in mind that the cause to my problems can be very basic and with a simple solution.

My problem is this: My Ubuntu/Apache2 server is hosting several sites and they work, throw no errors, but are occasionally very slow. The prime example of this is a Wordpress site, where both on the site itself and in the administration, sometimes you click a category and get a normally fast reponse and sometimes you click somewhere (where you've been 5 minutes ago) and the load takes 3-15 seconds. The server used to be fast all the time and now it isn't.

The server is not under any heavy kind of load (as far as I know), upload and download speeds are consistently maximum of table values of the connection.

Another issue (possibly related) is a very slow SSH login. This goes away if I disable reverse DNS lookup, but I have no idea if this is relevant.

Would it be helpful if I provided links to specific domains hosted on my server? Are there any logs/configs worth posting? I am glad to post whatever is required. If there is any information I can provide, let me know.

Thank you for any help you might be able to provide.


By rough estimate is seems to have helped a little when I added entries into /etc/hosts that forward every root domain with a Wordpress site to, but

  1. it didn't SOLVE the problem, only made it possibly a tad smaller
  2. it would probably be a crude workaround to a real problem elsewhere even if it worked
  • 2
    "This goes away if I disable reverse DNS lookup, but I have no idea if this is relevant." -- this is the basis for your entire problem. Fix your DNS setup and both problems will be solved, otherwise turn off rDNS lookup for both SSH and Apache. – womble Apr 14 '16 at 1:00
  • My /etc/apache2/apache2.conf already includes HostnameLookups Off. Is there anything else I can do to turn off rDNS? – erthy Apr 14 '16 at 1:26

This behavior is common if you have a memory leak in a plugin. This results in memory starvation, and the server threads start paging in and out of memory. It can also happen if you allow too many threads as Apache will spawn new threads as load goes up. There are a number of settings that can be used to work around the issue.

  • Setting MaxRequestWorkers to a smaller level will limit the number of threads. It should be small enough that all the worker threads fit in memory with room to spare.
  • Setting MaxConnectionsPerChild to a smaller level should limit the impact of a memory leak. If you suspect a memory leak try a value of 100 or 200 for a while.
  • You can set a hard memory limit in limits.conf that will cause threads to die if too much memory is leaked.
  • Adjusting MaxSpareServers may help. If it is too low, you may be frequently spawning new servers. If it too high, then you may increase memory paging.

It is possible some other process is consuming the memory and this is causing apache to page. If the server is not a dedicated webserver, then any other processes or combination of processes can cause this issue.

Virtual machines can be paged by the host system if it needs memory. The behavior will be much the same as if the virtual machine was running short of memory.

Running atsar often helps identify resource limitations. Examine the captured output with sar selecting the time period when you experience issues.

  • We have tried fiddling with all of these to no avail, except for the limits, however the server serves barely 3 wordpress instalations and some static sites, usage is low-to-none, it has 16 GB of memory and an ssd drive. So I am afraid it is not related to resource limitations. My best guess is still something DNS related, but both dig and host seem to report okayish results in 12-90 ms. I wonder what this could be caused by. – erthy Apr 18 '16 at 3:05
  • @ethy Unless you have enabled HostNameLookups, DNS should not be an issue for the apache2 web server. It is common for SSH logins to be slow if PTR lookups for the connecting server are slow. Unfortunately, many IP addresses do not have a DNS server for PTR records leading to timeouts on lookup. Do your access logs indicate that response times vary significantly? Your question does indicate you likely have problems with PTR records for your location, many of your clients may not have this issue. – BillThor Apr 18 '16 at 4:44
  • You wrote: Do your access logs indicate that response times vary significantly?` How would I know it this is the case? – erthy Apr 19 '16 at 5:24
  • @erthy You may need to modify the log format to report the time taken. I replace the %l field with %T (time taken seconds). Finer timing is generated if you use %{ms}T on Apache 2.4.13+, or %D. – BillThor Apr 20 '16 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.