Friday, June 6, 2008

My Dream Server for Django: Apache with mod_python,lighttpd,memcache

Whenever you start doing some projects, you don't want to rewrite the whole thing again after it is completed just to improve its server performance. You want to build in a solid base . The best way to take utmost from the django framework is to use Apache2 and mod_python to serve Django, and lighttpd to serve static media, memcache as caching backend and a good database(like sqlite,mysql,postgre ,etc).(probably that's what sites like youtube,sourceforge,wikipedia does)

Apache is a winner in terms of features and modules available.The main problem with using apache as a sole server is its memory imprint and heavy load.Its performance degrades under heavy load.Lighthttpd, on the other hand, is small, so its memory and cpu consumptions are smaller.But it doesn't provide you with flexibility of apache.

lighttpd (pronounced lighty) is a web server which is designed to be secure, fast, standards-compliant, and flexible while being optimized for speed-critical environments. Its low memory footprint (compared to other web servers), light CPU load and its speed goals make lighttpd suitable for servers that are suffering load problems, or for serving static media separately from dynamic content.It also has advanced feature set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more).

Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.It is by far the fastest, most efficient type of cache available to Django.Then,we need to get python-memcached, which is a python memcached client. There is an alternate cmemcached library for Python that is twice as fast as python-memcached but it works only under django development version. You can get python-memcached here: http://www.danga.com/memcached/)
To use Memcached with Django, set CACHE_BACKEND to memcached://ip:port/, where ip is the IP address of the Memcached daemon and port is the port on which Memcached is running.The default port is 11211.

Now for configuring apache and lighty for django, who better to tutor than the guys themselves.
visit http://www.djangoproject.com/documentation/fastcgi/ for a detailed instruction.

And there you are with your dream combination to work with django.

Stumble Upon Toolbar

0 comments: