Question

I will be deploying my django project on the server. For that purpose I plan on doing the following optimization.

  • What i would like to know is that am I missing something?
  • How can I do it in a better manner?

Front-end:

  1. Django-static (For compressing static media)
  2. Running jquery from CDN
  3. Cache control for headers
  4. Indexing the Django db (For certain models)

Server side:

  1. uswgi and nginx .
  2. Memcached (For certain queries)
  3. Putting the media and database on separate servers
Was it helpful?

Solution

These are some optimization I use on a regular basis:

frontend:

  1. Use a js loading library like labjs, requirejs or yepnope. You should still compress/merge your js files, but in most use cases it seems to be better to make several requests to several js files and run them in parallel as to have 1 huge js file to run on each page. I always split them up in groups that make sense to balance requests and parellel loading. Some also allow for conditional loading and failovers (i.e. if for some reason, your cdn'd jquery is not there anymore)

  2. Use sprites where posible.

Backend:

  1. configure django-compressor (django-static is fine)
  2. Enable gzip compression in nginx.
  3. If you are using postgresql (which is the recommended sql database), use something like pgbouncer or pgpool2.
  4. Use and configure cache (I use redis)
  5. (already mentioned - use celery for everything that might take longer)
  6. Small database work: use indexes where it's needed, look out for making too many queries (common when not using select_related where you are supposed to) or slow queries (enable log slow queries in your db). Always use select_related with arguments.
  7. If implementing search, I always use a standalone search engine. (elasticsearch/solr)
  8. Now comes profiling the app and looking for code specific improvements. Some things to keep an eye on.

OTHER TIPS

An option may be installing Celery if you need to support asynchronous & period tasks. If you do so, consider installing Redis instead of Memcached. Using Redis you can manage sessions and carry out Celery operations as well as do caching.

Take a look at here: http://unfoldthat.com/2011/09/14/try-redis-instead.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top