Optimal Python/Django deployment setup for Linode 360

Hello,

I'm moving a Django application from shared hosting to Linode. The website receives about 10k page views per day and it has a relatively simple database model. I've signed up for a Linode 360 and I'm currently investigating deployment options. After some research, I've collected the following pieces of information:
* Apache + modwsgi is the official way of deploying Django. modwsgi offers serious advantages over other deployment options, like better process handling. [1] [2] [3]

  • Apache may be too bloated for a Linode 360. Many people at Linode prefer nginx or lighttpd.

  • nginx has a mod_wsgi module, but it seems to have many limitations. [4]
    My Linode will host the website and its database only. I'm currently leaning towards trying Apache. I will do some load tests before making the final decision. But I'm curious to see what others are using and would like to hear their opinions.

I'm sure there are many Python users here. Would you please share your Linode type, website setup and size? There is very little documentation on running Python web applications at Linode. If we get a good number of responses, I'm sure this post will be valuable for new Linode/Python users.

Thanks.

3 Replies

@django_user:

Apache may be too bloated for a Linode 360.
I disagree with this. Apache has a bad rap because of the default configuration that is shipped with most major distributions. Apache can be tuned to sing carols on a Linode 360, right alongside MySQL (similarly tuned).

Among my top 3 languages that I work in regularly, Python is number 2 these days – and when I dabbled in Django, I followed their recommendation precisely and used Apache and mod_wsgi. I've also had success adapting the Lighttpd section of this guide to nginx, as well. Your mileage may vary.

I just hate seeing folks immediately write off Apache because it's "bloated"; it's not Apache that's bloated, it's the things that we add to each Apache process. Along those lines, I think there's a general lack of knowledge regarding tuning Apache. I regularly see folks who apparently don't touch the Apache configuration after they install it, and are then surprised when the OOM killer starts tearing up their setup.

Instead of relying on the small "get up and running" tutorials (even the Linode Library – by all means use it, but don't use it solely), a wise system administrator will fully read the documentation for a product and understand it before putting a product in heavy production. I feel there is too little of this today, due to various things – most of them misdiagnosed as ADD and the inability to focus for long periods of time. (I suffer from this, and I don't think it's ADD.)

That's what happens with Apache. Someone follows a quick start guide and never touches the configuration again, they run out of memory on their equipment and the entire stack goes down, then Apache gains a reputation as being bloated.

Sorry to tangent from your original question!

@django_user:

nginx has a modwsgi module, but it seems to have many limitations. You don't have to run Django via modwsgi under nginx. The way I ran PHP under nginx (which helped Wordpress survive Slashdot on a Linode 540) was via FastCGI. Python can be coerced to do FastCGI, but it doesn't have built-in support for it like PHP does. There's a few guides out there that I've adapted to my needs; I regularly come back to this one.

@django_user:

I'm currently leaning towards trying Apache. I will do some load tests before making the final decision. But I'm curious to see what others are using and would like to hear their opinions.
Install Apache, slash MaxClients down quite a bit, and (for prefork MPM) make sure Apache doesn't spawn more than a few processes with mod_anything. How many req/min does your site do right now?

@django_user:

Would you please share your Linode type, website setup and size?
When I ran Django, I did Apache with mod_wsgi and MySQL on a Linode 360. It was for development, so I tuned it to handle two concurrent requests – with that setup, I had about 150 MB of RAM remaining for cache (and the Linode was doing some other things).

As far as Apache on a Linode 360, I had our server set up to serve only images and an occasional PHP page. We have fairly high traffic and this is our ad server. I've had it set to

KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 3

 <ifmodule mpm_prefork_module="">StartServers          50
    MinSpareServers       25
    MaxSpareServers      100
    ServerLimit         400
    MaxClients          400
    MaxRequestsPerChild  20000</ifmodule> 

and this has been perfectly fine! I didn't have any problems on the 360 until I foolishly let it run out of disk space, due to being an inobservant log hoarder.

I upgraded to a 720 recently only because we were using 400GB of bandwidth a month anyway (though linode's policy of charging the same rate was working out excellently for us) and because we wanted more disk space to hoard logs on.

We usually have between 160 and 250 Apache processes in use at any time. I know we could do better with nginx or lighthttpd since it's just images, but I've just stayed with Apache since resource usage is not a problem for us.

No experience running Django on anything other than my home system so far, so unfortunately can't add anything there, but I wanted to point out there are enough resources on a 360 to handle Apache. We're serving up 40 million images a month from ours.

I run, uh, 5 Django powered sites on a 540 using ./manage.py runfcgi, and Lighty's fcgi socket support.

I'm also running MySQL, PostgreSQL, *, Jetty, ejabberd, Postfix, and Dovecot, and have 360+81 MB used.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct