If you are deploying a simple website that will receive only a small amount of traffic, the simple deployment we have discussed so far will suffice. However, as a site receives more and more traffic, you will want to optimize your deployment to make it as efficient as possible.
You can do several things to optimize the Django deployment. The following sections discuss several optimizations that you can use to improve your website's performance.
One of the best optimizations you can do is move the database to a server separate from the Django deployment. As the website starts being used heavily, a web server and database on the same server will begin to experience resource contention for memory, processes, and file access. Moving the database to a separate server eliminates that contention.
Another of the best optimizations you can do is move the media to a server separate from the Django deployment. If your website has a large amount of media being served, moving all media that is not being generated by Django views to a separate server results in a big performance boost.
Installed middleware frameworks are processed for every request that is sent to the server. Even if those frameworks perform only small operations, as the number of requests grows, so does the performance hit incurred by the framework. Removing any unnecessary middleware has a big effect on performance in a heavily used website. For example, if your website doesn't need to use user authentication, the AuthenticationMiddleware shouldn't be installed.
Caching web pages can provide another boost to web server performance, especially if you use the Memcached backend. Memcached is by far the fastest caching backend.
Hour 23, "Configuring Caching," describes how to configure the caching backends and implement caching in your Django installation. You should optimize caching as much as possible if performance is a must for your website.
Heavily used websites can never have enough RAM. One of the easiest, and usually most cost-effective, methods of optimizing your web server is adding RAM.