Probably a simple thing — slow apache

Posted on

Probably a simple thing — slow apache – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, ubuntu, , , .

I am trying to run a Django webapp with Apache and mod-wsgi. Every page take a solid 10 seconds to load. I’ve ruled out the MySQL database (enabled slow querie logging and they are all fast) so I think that I have an issue with DNS settings. I have the server in my office and I’m trying to access the webapp from within the same office LAN. When I run the webapp on the Django test server it is lightening fast, so I’m convinced it’s apache or my networking settings somehow.

My hosts file looks like this:

127.0.0.1       localhost
127.0.1.1       localhost
192.168.47.140  RDCServer
192.168.47.140  app.my_domain.com

The app.my_domain.com is the sub-domain of the webapp, the main domain is the main website which is located on a VPS server (different IP addy)

What am I doing wrong?

Solution :

Make sure you aren’t using mod_wsgi in embedded mode, especially with Apache prefork MPM. If you are then you may be hitting a different process for every request and seeing the delay in loading Django the first time. If this were the case though you might expect that after a while as Django gets loaded, that response times then drop. This is not absolute though because if request load is very light, depending on how you have set up Apache, Apache could decide your processes aren’t needed and shut them down, meaning that on subsequent requests after idle period, it is loading the whole of Django once again.

Ensure you are using:

LogLevel info

in Apache configuration so that mod_wsgi logs stuff about when it is initialising Python in processes and loading WSGI script for first time. That will at least help you to eliminate that as the issue.

Better still, if you don’t know much about setting up Apache or mod_wsgi, use daemon mode of mod_wsgi as that will save you from many of the mistakes you can make in setting up Apache badly for Python web applications.

Thanks for the responses. I checked into your suggestions and determined it to be an issue with my server’s hosts file. I added the IP address of my router with the myapp.my_domain.com and all is now well.

123.345.567.678    myapp.my_domain.com

Is this a poor solution or does it makes sense?

In any event, it is working. Thanks!

(Better title for your question: How do I diagnose apache taking 10 seconds for each page?)

Use chrome’s web dev tools to determine exactly (from the client’s perspective) what’s slow.

If it’s Apache, turn on ALL apache debugging and run it in the foreground. This ought to give you more hints as to what its doing.

Do you get the delay serving static resources? Or only WSGI requests?

You need to isolate the problem first, you’re trying to debug this through trial and error.

Majority of times, when the sites are not loading correctly, then the Simples and basic disagnostic tool is our BROWSER.
it tells you a lot about what it is doing with the site you gave it to process and display.
for example, in chrome browser, when you have typed the address of site, then just after pressing enter button, keep an eye on the status bar of chrome.
it might be telling you any of these:
– ” waiting for app.my_domain.com…”
– “resolving app.my_domain.com”
if its the first case, then it tells us that your DNS is 100% healthy. and if it takes 10 seconds stuck at showing “Resolving….” that means DNS is the culprit.

You can use Firebug in forefox or chrome, to see detailed debug of exactly where it is taking so much time.

Leave a Reply

Your email address will not be published. Required fields are marked *