Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx cache, staticgenerator vs memcached

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).
    • Edit: After looking at other solutions (such as: http://soyrex.com/articles/django-nginx-memcached/) I find that there seems no need to use md5 cache_keys. Maybe this should be an option.
  • 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?

like image 697
demux Avatar asked May 29 '26 01:05

demux


1 Answers

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?

like image 118
demux Avatar answered Jun 01 '26 15:06

demux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!