JasonTS
JasonTS

Reputation: 2589

Serve multiple Django and PHP projects on the same machine?

The documentation states that one should not server static files on the same machine as as the Django project, because static content will kick the Django application out of memory. Does this problem also come from having multiple Django projects on one server ? Should I combine all my Website-Projects into one very large Django project ?

I'm currently serving Django along with php scripts from Apache with mod WSGI. Does this also cause a loss of efficiency ?

Or is the warning just meant for static content, because the problem arises when serving hundreds of files, while serving 20-30 different PHP / Django projects is ok ?

Upvotes: 0

Views: 575

Answers (2)

Graham Dumpleton
Graham Dumpleton

Reputation: 58553

If the documentation says """one should not server static files on the same machine as as the Django project, because static content will kick the Django application out of memory""" then the documentation is very misleading and arguably plain wrong.

The one suggestion I would make if using PHP on same system is that you ensure you are using mod_wsgi daemon mode for running the Python web application and even one daemon process per Python web application.

Do not run the Python web application in embedded mode because that means you are running stuff in same process as mod_php and because PHP including extensions is not really multithread safe that means you have to be running prefork MPM. Running Python web applications embedded in Apache when running prefork MPM is a bad idea unless you know very well how to set up Apache properly for it. Don't set up Apache right and you get issues like as described in:

http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html

The short of it is that Apache configuration for PHP and Python need to be quite different. You can get around that though by using mod_wsgi daemon mode for the Python web application.

Upvotes: 0

ohrstrom
ohrstrom

Reputation: 2970

I would say that this setup is completely ok. Off course it depends on the hardware, load and the other projects. But here you can just try and monitor the usage/performance.
The suggestion to use different server(s) for static files makes sense, as it is more efficient for the ressources. But as long as one server performs good enough i don't see a reason to use a second one.

Another question - which has less to do with performance than with ease of use/configuration - is the decision if you really want to run everything on the same server.

For one setup with a bunch of smaller sites (and as well some php-legacy) we use one machine with four virtual servers:

  • webhead running nginx (and varnish)
  • database
  • simple apache2/php server
  • django server using gunicorn + supervisord

nginx handles all the sites, either proxying to the application-server or serving static content (via nas). I like this setup, as it is very easy to install and handle, as well it makes it simple to scale out one piece if needed. Bu

Upvotes: 2

Related Questions