Django

Django, Python frameworks and VPS hosting

The highlight this week is that I’ve actually started writing code. I’ve also selected Django as the development framework and chosen a VPS to run it on…

It’s been almost a month since I last posted here (so much for weekly goal reviews), but not because I’ve been slacking - there’s been a lot of real world activity of late, mostly of the birthdays and weddings variety, and there has also been progress on the geo development front.

Unfortunately time was a little too tight and something had to give - and it was writing blog posts.

Looking back on these original geo goals, they seem like a distant memory. The plan has evolved into something which I think is quite original, a huge advance on the directory sites of old, something quite cool indeed (More details at a later date).

A big influence over this time has been a very cool book called Flip (aff link); If you are interested in quality - I recommend it.

I’ve also done a lot of research into application frameworks. One of my was to develop a project in rails or a similar framework, well after much research - I have settled on Django.

I initially considered ruby on rails (the trendy framework du jour), pylons, turbogears, and django; You may not have heard of the last three, but they are all python frameworks.

Python is behind more massive websites than you are probably aware of, Google and Youtube for example. One reason for this may be because python is incredibly fast for such a high level language.

I’ve had some experience in Python - and I enjoyed it, it’s not massively dissimilar to ruby, although I’d argue that it is better documented - and has a sense of humor. It’s also has a refreshingly prescriptive philosophy; the following is the ‘tao of python’:

1. Beautiful is better than ugly.
2. Explicit is better than implicit.
3. Simple is better than complex.
4. Complex is better than complicated.
5. Flat is better than nested.
6. Sparse is better than dense.
7. Readability counts.
8. Special cases aren’t special enough to break the rules.
9. Although practicality beats purity.
10. Errors should never pass silently.
11. Unless explicitly silenced.
12. In the face of ambiguity, refuse the temptation to guess.
13. There should be one— and preferably only one —obvious way to do it.
14. Although that way may not be obvious at first unless you’re Dutch.
15. Now is better than never.
16. Although never is often better than *right* now.
17. If the implementation is hard to explain, it’s a bad idea.
18. If the implementation is easy to explain, it may be a good idea.
19. Namespaces are one honking great idea — let’s do more of those!

To cut a long story short, I chose python over ruby (a personal preference).

This left me with Pylons, Turbogears and Django.

To non python programmers, there’s not a lot of difference between Pylons and Turbogears. They are both full stack MVC type affairs, the key difference being Pylons takes ‘best of breed’ components and combines them into a framework, as opposed to Turbogears which is made up of components written especially for turbogears.

I won’t elaborate further here, but if you are interested in comparing python frameworks, Adam Gomaa wrote an excellent (possibly seminal) paper on the conceptual integrity of frameworks discussing python; I highly recommend it.

After downloading django and running through the excellent tutorials, I quickly decided that this is the framework for me.

Django is under active development, and has considerable momentum at this point in time. Like rails, it is also derived from a real world website (rails came from basecamp).

Unfortunately, Django isn’t quite so easy to host as your average php application like wordpress or drupal. In fact- I would say that php’s greatest strength has been the simplicity with which one can write, test and deploy a php script to the Internet. Every single shared hosting account I can think of offers php hosting - because it is very easy to offer.

Unfortunately, Django is a bit harder. It’s recommended deployment platform is using mod_python on apache. Which is fine and dandy, except hardly any shared hosts offer mod_python (it is incredibly fast, but also very memory intensive).

Luckily, there is another more pragmatic way to run Django without requiring gigabytes of RAM, and that is using fastcgi. Many web servers support fastcgi, the three main ones to consider are lighttpd, nginx and trusty apache.

If memory isn’t a pressing issue, then apache would be the clear choice (and hence, possibly mod_python). Apache is light years ahead of any other web server in the history of mankind in terms of stability, speed (given enough resources - apache is as fast as anything), and manageability.

As anyone who has written an apache module (or a mod_python specific app) will testify, apache is brilliantly designed - and almost infinitely configurable.

However, unless you have the funds for a dedicated private server (a real one), or a VPS (Virtual Private Server) with plenty of memory (for example 2GB for a high volume sites) - then fastcgi is your plumbing of choice.

Given these decisions, I yesterday stumped up the princely sum of $20 for my first month of an Ubuntu (on xen) VPS with a whole 256MB of RAM from slicehost. I finally feel grown up - like I have been nannied all this time in shared hosting, now I have my own IP and my own whole entire Ubuntu server to play with. I love linux, and my fave distro is Ubuntu (because it’s easy to do the things that should be easy - the only other OS I can say this about is OSX, but I don’t think that’s really the ideal server).

I’ve already got django running, but have yet to decide between lightty (lighttpd) and nginx. At this stage I’m leaning toward nginx - mainly because there are unsubstantiated (and unrebutted) reports of memory leaks with lightty - and nginx is to my intents and purposes, functionally identical.

If anyone has a view on this, I’d love to hear it.I’ve also been reading up on keeping mysql memory under control. I need to save some memory for sphinx! My view is that if I can get this all running happily on a 256Mb VPS, with some moderate load testing - then at least I’ll have all the factors under control so that when I need to scale up with more memory - I’ll immediately be making the most of it, in terms of user experience.

If you enjoyed this article, please bookmark it using delicious or stumbleupon.

2 Comments

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*Required Fields