3

What I'm doing is avoiding having requests hit Django and serving cached data straight from nginx.
Related question: Django staticgenerator vs CACHE_BACKEND

There seem to be two choices when it comes to this:
https://github.com/torchbox/django-nginx-memcache
https://github.com/mrj0/staticgenerator - This one seems easier to use

After trying django-nginx-memcache I found some downsides:

  • No fallback to serve cached content from django (can be fixed).
  • nginx has to be recompiled for md5 sum generation of urls (I don't think this can be fixed).
  • It would be nice to be able to define a list of url patters that should be cached. So far, only decorators are available (can be fixed).
  • The code should in my opinion be modelled more after the standard django cache backend with UpdateCacheMiddleware and FetchFromCacheMiddleware. This would make it easier to implement nginx cache where standard django cache solutions exist. It would also solve problem #1 (can be fixed).
  • Strange naming of module. While the project is named django-nginx-memcache, the package is named Django-Memcache-for-Nginx and the app nginx_memcache for inclusion in django installed_apps (can be fixed).

Which is faster?
Which one would you use and why?
Should I fix the issues that I have with django-nginx-memcache or is staticgenerator just better anyway?

Community
  • 1
  • 1
demux
  • 4,544
  • 2
  • 32
  • 56

3 Answers3

1

This seems to answer all of my questions and provides a more elegant solution than django-nginx-memcache, that is patching the django cache system: http://www.willmcgugan.com/blog/tech/2009/3/1/fast-caching-with-django-and-nginx/

Benchmarks from comment on page:

Static content is almost 4x faster than serving from memcache with nginx.

Request rate: 6243.8 req/s (0.2 ms/req) (static html)

Request rate: 2285.5 req/s (0.4 ms/req) (same html in memcache)

I think I'll go with staticgenerator but please feel free to post your thoughts.

Edit:

I realized that I'm running two webservers in parallel and I would need a way to sync the cached data if I go with staticgenerator. I guess I could fork it and have it write the files on both servers through network. Any thoughts on this?

Community
  • 1
  • 1
demux
  • 4,544
  • 2
  • 32
  • 56
0

It seems you wan to cache generated pages. Have you tried Varnish ( https://www.varnish-cache.org/ ).

Sometime back I was researching caching for Django and i found this article about using Varnish cache to cache generated pages. http://ghughes.com/blog/2011/11/11/using-varnish-with-django-for-high-performance-caching/

May be it will work for you.

Nitin Bhide
  • 1,685
  • 14
  • 15
  • 1
    I did try varnish and I liked it, thank you. I'm researching other solutions. Using nginx in combination with memcached or generated static files won't deliver better performance than varnish but it will give me more flexibility and eliminate the overhead of having to configure two different servers. – demux Sep 06 '12 at 06:12
0

In the spirit of keeping things simple, how about just using the cache directives in Nginx' Proxy module?

Along the lines of https://serverfault.com/a/68160/46143 and http://www.rfxn.com/nginx-caching-proxy/

Community
  • 1
  • 1
eevar
  • 3,519
  • 1
  • 19
  • 9