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

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

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

我的问题:

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


当前回答

我用Django为爱尔兰国家广播公司开发高流量网站。这对我们来说很有效。开发一个高性能的网站不仅仅是选择一个框架。框架只是系统的一部分,它的强大程度取决于它最薄弱的环节。如果问题是数据库查询缓慢或服务器或网络配置糟糕,使用最新的框架'X'将无法解决您的性能问题。

其他回答

是的,它可以。它可以是Django with Python或Ruby on Rails。它仍然会缩放。

有几种不同的技术。首先,缓存不是可伸缩性。除了硬件平衡器之外,还可以有多个应用服务器以nginx作为前端平衡。 为了在数据库端扩展,如果你走RDBMS的路,你可以在MySQL / PostgreSQL中使用读从。

Django中一些大流量网站的例子如下:

当他们还在那里的时候。 通用共享评论管理器 所有与报纸相关的网站:《华盛顿邮报》等。

你会有安全感。

尽管这里有很多很棒的答案,我只是想指出,没有人强调…

这取决于应用程序

如果你的应用程序写得比较少,因为你从DB中读取的数据比写的数据要多得多。然后缩放django应该是相当简单的,见鬼,它带来了一些相当不错的输出/视图缓存直接开箱即用。利用这一点,比如说,redis作为一个缓存提供商,在它前面放置一个负载均衡器,旋转n个实例,你应该能够处理非常大量的流量。

现在,如果你一秒钟要做几千个复杂的写?不同的故事。Django是一个糟糕的选择吗?好吧,不一定,这取决于您如何构建解决方案,以及您的需求是什么。

这只是我的个人意见:-)

我们正在进行负载测试。我们认为我们可以支持240个并发请求(24x7每秒120次的持续速率),而不会显著降低服务器性能。那就是每小时432000次点击。响应时间并不小(我们的事务很大),但随着负载的增加,基线性能没有下降。

我们使用Apache前端Django和MySQL。操作系统为Red Hat Enterprise Linux (RHEL)。64位。我们在Django的守护模式下使用mod_wsgi。除了接受默认值外,我们没有做任何缓存或数据库优化。

我们都在一台64位戴尔的虚拟机中,(我想)有32Gb内存。

因为对于20或200个并发用户来说,性能几乎是相同的,所以我们不需要花费大量时间进行“调整”。相反,我们只需要通过普通的SSL性能改进、普通的数据库设计和实现(索引等)、普通的防火墙性能改进等来保持我们的基础性能。

我们测量的是我们的负载测试笔记本电脑在15个进程运行16个并发请求线程的疯狂工作负载下挣扎。

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

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

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

"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数据。


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