2

I work in a SaaS application built with Django (Python) and runs with Apache/mod_wsgi.

The registration site creates an apache virtual host config, wsgi and settings files. And finally restarts the apache server.

This means that every time a new user registers an account apache restarts and this affect the performance of the app for the current clients.

A possible option is to create a separate apache instance for new clients how ever this will increase too much the RAM needed for all clients.

What recommendations do you have about this?

1
  • Sounds dangerous. A bad registration could bring the website down.
    – hookenz
    Nov 22, 2010 at 23:51

3 Answers 3

3

The side effect of several instances is that they all can't run on the same port either.

Maybe your script can do a "apachectl configtest" to ensure the configuration is valid first (helping prevent it not starting due to error in config).

And then run apachectl graceful.

apachectl graceful: Gracefully restarts the Apache daemon by sending it a SIGUSR1. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files via configtest before initiating the restart to make sure Apache doesn't die.

apachectl configtest: Run a configuration file syntax test. It parses the configuration files and either reports Syntax Ok or detailed information about the particular syntax error.

1
  • I never thought about a dangerous registration, I like the key tip about check first, and then a graceful restart. Thanks
    – quarry32
    Nov 24, 2010 at 0:45
0

This is probably overkill, but I have a cunning plan. :-)

Set up an iptables rule such as:

iptables -t nat -i PREROUTING -m tcp -p tcp --dport 80 -j DNAT --to-destination :81

Have Apache running on port 81. Incoming connections for port 80 would get redirected to port 81.

Now, when you get a new configuration, save it to a separate location and have it listen on port 82. Now you can try starting a second instance of Apache. If it fails to start, you know you have a configuration problem and can continue running with the old configuration until it is resolved.

If it does start, replace the iptables rule above with one pointing at port 82. Existing connections will continue to go to the old port until they are complete. Give them some grace period before shutting down the old instance. In this way you start a completely new instance and shut down the old one, but without interrupting users. Then you can do the same with the next configuration going back to port 81.

apachectl graceful is probably what you want, but if it doesn't work out for you this may be another option.

0

You'll find that with Apache/mod_wsgi, it is version-locked to the version of Django. So if you have Python 2 code with mod_wsgi2, you'll have to have a separate instance of httpd with mod_wsgi3 if you also have Python 3 code.

I don't know how fine the match has to be, but I think I've been told to expect to have another instance of Apache soon as we finish migrating from 2 to 3, and then 3.next. Add to that and other module conflicts on the same box for some other middleware, and that box has three httpd instances currently.

Hopefully your site would be redundant, and you could restart one side at a time. You should multiplex between the sites with a reverse-proxy, perhaps httpd with something like mod_cluster.

And what about the process-space inside mod_wsgi? Are two clients isolated from each other in a secure manner if they are managed by the same httpd instance?

If I had the choice, I'd perhap go with a FastCGI deployment.... I think Django can do that (with gunicorn?), but its been some time since we looked, and I wasn't the one doing the looking.

Hope that helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .