我正在用Django构建一个web应用程序。我选择Django的原因是:

我想使用免费/开源工具。 我喜欢Python,觉得它是一种长期的语言,而对于Ruby,我不确定,而PHP似乎是一个巨大的麻烦。 我正在为一个想法构建一个原型,并没有过多地考虑未来。开发速度是主要因素,而且我已经了解Python。 我知道迁移到谷歌应用程序引擎将更容易,如果我选择这样做在未来。 我听说Django很“不错”。

现在我越来越接近于考虑出版我的作品,我开始担心规模问题。我找到的关于Django伸缩能力的唯一信息是Django团队提供的(我不是说什么要忽略它们,但这显然不是客观的信息…)

我的问题:

目前在Django上构建的“最大”站点是什么?(我主要通过用户流量来衡量规模) Django能每天处理10万名用户,每个用户访问站点几个小时吗? 像Stack Overflow这样的站点可以在Django上运行吗?


当前回答

下面是Django中构建的一些相对高调的东西:

《卫报》的“调查你的议员的开支”应用程序 Politifact.com(这里有一篇博客文章谈论了(积极的)体验。Site获得了普利策奖。 《纽约时报》的代表应用 EveryBlock WaPo的程序员之一Peter Harkins在他的博客上列出了他们用Django构建的所有东西 它有点老了,但是《洛杉矶时报》的人给出了他们为什么选择Django的基本概述。 洋葱的AV俱乐部最近从(我想是Drupal)转移到了Django。

我想很多这样的网站每天的点击率都超过了10万。Django当然可以达到10万/天甚至更多的点击量。但是YMMV的作用取决于你要建什么。

在Django级别有缓存选项(例如在memcached中缓存查询集和视图可以创造奇迹)和其他级别(如Squid这样的上游缓存)。数据库服务器规范也将是一个因素(通常是挥霍的地方),以及您对它的调优情况。例如,不要想当然地认为Django会正确地建立索引。不要认为默认的PostgreSQL或MySQL配置就是正确的。

此外,如果Django运行速度慢,您总是可以选择让多个应用服务器运行Django,并在前面安装一个软件或硬件负载均衡器。

最后,静态内容和Django是在同一个服务器上提供的吗?你用的是Apache还是nginx或者lighttpd?你能负担得起为静态内容使用CDN吗?这些都是需要考虑的问题,但都是很有推测性的。每天10万点击量并不是唯一的变量:你想花多少钱?管理所有这些组件,您有多少专业知识?你有多少时间把这些都整理好?

其他回答

我所知道的最大的django网站是华盛顿邮报,这肯定表明它可以很好地扩展。

好的设计决策对性能的影响可能比其他任何东西都要大。Twitter经常被认为是另一个基于动态解释语言的web框架——Ruby on Rails——体现了性能问题的站点——但Twitter工程师表示,该框架并不像他们早期所做的一些数据库设计选择那样是个大问题。

Django可以很好地使用memcached,并提供了一些管理缓存的类,这可以解决大部分性能问题。在现实中,你在网络上交付的东西几乎比你的后端更重要——使用像yslow这样的工具对于高性能web应用程序来说是至关重要的。你可以在后台添加更多硬件,但你不能改变你的用户带宽。

"What are the largest sites built on Django today?" There isn't any single place that collects information about traffic on Django built sites, so I'll have to take a stab at it using data from various locations. First, we have a list of Django sites on the front page of the main Django project page and then a list of Django built sites at djangosites.org. Going through the lists and picking some that I know have decent traffic we see: Instagram: What Powers Instagram: Hundreds of Instances, Dozens of Technologies. Pinterest: Alexa rank 37 (21.4.2015) and 70 Million users in 2013 Bitbucket: 200TB of Code and 2.500.000 Users Disqus: Serving 400 million people with Python. curse.com: 600k daily visits. tabblo.com: 44k daily visits, see Ned Batchelder's posts Infrastructure for modern web sites. chesspark.com: Alexa rank about 179k. pownce.com (no longer active): alexa rank about 65k. Mike Malone of Pownce, in his EuroDjangoCon presentation on Scaling Django Web Apps says "hundreds of hits per second". This is a very good presentation on how to scale Django, and makes some good points including (current) shortcomings in Django scalability. HP had a site built with Django 1.5: ePrint center. However, as for novemer/2015 the entire website was migrated and this link is just a redirect. This website was a world-wide service attending subscription to Instant Ink and related services HP offered (*). "Can Django deal with 100,000 users daily, each visiting the site for a couple of hours?" Yes, see above. "Could a site like Stack Overflow run on Django?" My gut feeling is yes but, as others answered and Mike Malone mentions in his presentation, database design is critical. Strong proof might also be found at www.cnprog.com if we can find any reliable traffic stats. Anyway, it's not just something that will happen by throwing together a bunch of Django models :)

当然,还有更多感兴趣的网站和博主,但我必须在某个地方停下来!


一篇关于使用Django构建高流量网站michaelmoore.com的博文,将其描述为排名前10,000的网站。Quantcast数据和compete.com数据。


(*)编辑的作者,包括这些引用,曾经在该项目中作为外包开发人员工作。

问题是不知道django是否可以伸缩。

正确的方法是理解和知道哪些网络设计模式和工具应该放在django/symfony/rails项目下,以实现良好的扩展性。

一些想法可以是:

多路复用。 反向代理。例如:Nginx,清漆 Memcache会话。例如:Redis 在项目和数据库上进行集群化,以实现负载平衡和容错:例如:Docker 使用第三方存储资产。例子:Amazon S3

希望它能有所帮助。这是我的小石头。

你完全可以用Django运行一个高流量的站点。看看这篇在django 1.0之前但仍然相关的文章:http://menendez.com/blog/launching-high-performance-django-site/

不知道每天的访问量有多少,但这里有一些大型Django站点的例子:

Disqus.com(来自djangocon的演讲) bitbucket。org(写作) lanyrd.com(源) support网站(源代码) Addons.mozilla.org(源代码)(来自django的谈话) Theonion.com网站 uk评论系统使用Django(来源) instagram pinterest rdio

这里是Quora上高流量Django网站的链接。