nginx缓存,staticgenerator vs memcached

时间:2012-09-06 05:56:54

标签: django caching nginx memcached

我正在做的是避免请求点击Django并直接从nginx提供缓存数据。
相关问题:Django staticgenerator vs CACHE_BACKEND

在这方面似乎有两种选择:
https://github.com/torchbox/django-nginx-memcache
https://github.com/mrj0/staticgenerator - 这个似乎更容易使用

尝试django-nginx-memcache后,我发现了一些缺点:

  • 没有后备从django提供缓存内容(可以修复)。
  • nginx必须重新编译为md5总和生成网址(我不认为这可以修复)。
  • 能够定义应该缓存的url模式列表会很高兴。到目前为止,只有装饰器可用(可以修复)。
  • 在我看来,代码应该在使用 UpdateCacheMiddleware FetchFromCacheMiddleware 的标准django缓存后端之后进行更多建模。这样可以更容易地实现存在标准django缓存解决方案的nginx缓存。它还可以解决问题#1(可以修复)。
  • 模块的奇怪命名。当项目名为 django-nginx-memcache 时,该软件包名为 Django-Memcache-for-Nginx ,应用程序 nginx_memcache 包含在django installed_apps(可以修复)。

哪个更快?
你会使用哪一个?为什么? 我应该用 django-nginx-memcache staticgenerator 来解决我的问题呢?

3 个答案:

答案 0 :(得分:1)

这似乎回答了我的所有问题,提供了比 django-nginx-memcache 更优雅的解决方案,即修补django缓存系统:http://www.willmcgugan.com/blog/tech/2009/3/1/fast-caching-with-django-and-nginx/

来自评论页面的基准:

静态内容几乎比使用nginx的memcache快4倍。

请求率:6243.8 req / s(0.2 ms / req)(静态html)

请求率:2285.5 req / s(0.4 ms / req)(在memcache中使用相同的html)

我想我会选择 staticgenerator ,但请随时发表您的想法。

编辑:

我意识到我正在并行运行两个Web服务器,如果我选择 staticgenerator ,我需要一种方法来同步缓存的数据。我想我可以把它分叉并让它通过网络在两台服务器上写文件。有什么想法吗?

答案 1 :(得分:0)

您似乎想要缓存生成的页面。你试过Varnish(https://www.varnish-cache.org/)吗?

有时候我正在研究Django的缓存,我发现这篇文章关于使用Varnish缓存来缓存生成的页面。 http://ghughes.com/blog/2011/11/11/using-varnish-with-django-for-high-performance-caching/

可能适合你。

答案 2 :(得分:0)

本着保持简单的精神,如何在Nginx的代理模块中使用缓存指令?

https://serverfault.com/a/68160/46143http://www.rfxn.com/nginx-caching-proxy/

一致