search
HomeBackend DevelopmentPython Tutorial为什么 Dropbox 等大型服务使用 Python 作为主要语言,即使它的效率比其他编译型语言低几个数量级?

回复内容:

任何“XXX语言太慢”的观念都是以偏概全。
应用程序分很多种,CPU bound, I/O bound, Memory bound, 等等。如果你的程序属于I/O bound,即使你把整个程序换成手工优化过的C,速度不会有本质提升。
对于Dropbox来说,其业务逻辑不复杂,性能瓶颈显然在I/O. 除了我估计判重时的 SHA 运算量比较大,但 CPython 的一大优势便是很容易使用 C 写模块,找到 hot spot 后再用 C 来写也不迟。"Premature optimization is the root of all evil."
既然如此,使用一种性能稍差但易读易写、生态系统完善、跨平台、迭代迅速的语言便是顺理成章的了。
更何况,Guido, Python 的作者,已经被 Dropbox 挖走了。
Python的确比compiled languages(编译型语言)慢几个数量级,但这只与受CPU限制的应用有关。
Dropbox主要受磁盘和网络约束。因此,使用编译型语言并不会明显加快Dropbox,因为大部分时间都花在读写数据而不是计算上。

解释型语言的优点在于开发速度,这也是为什么大多数网站都用解释型语言​作开发。当这些缺点被边缘化时,程序员从这些优点上受益。

参考资料:
William Ting's answer to Python (programming language): How can some really large services (like Dropbox) afford to use Python as a primary language, if it's one to two orders of magnitude slower than other, compiled languages? 大型服务使用 Python 作为主要语言的,我知道比较有名的是 Dropbox,YouTube,Quora 和知乎。其实分析Dropbox和YouTube为啥使用 Python意义并不大,因为Dropbox的文件同步和 YouTube 的在线视频这种核心的功能,我相信都不是用 Python 来完成的。

反而分析 Quora 和知乎为什么采用 Python 作为主要语言,相对更加准确一些,Quora为什么使用Python,我引用Quora创始人Adam D'Angelo和Charlie Cheever在Quora上的现身说法,知乎为什么使用Python,还请知乎的大牛们现身说法一下。

Adam 在回答中提到,他当初从 Facebook 离职创办 Quora,首先就排除了 PHP,因为作为 Facebook 前 CTO 的他深知PHP 所带来的痛苦;他也考虑过C#,Java,甚至小众的Scala,OCaml 和Haskell,排除C#是不想受限于微软的协议栈,Java 需要的开发周期更长,同时找到熟手较难。最后选择 Python 的原因其实很简单:Adam和另一个创始人Charlie对于 Python 都比较熟悉!

从后面多年的使用情况来看,Adam非常庆幸当初自己的选择:所有的员工都很高兴使用 Python,不管以前的主要语言是什么;Tornado等框架的推出,让更新等实时服务有了好的去处;PyPy可能在不久的将来让 Python 性能有一次大的提升,在这个理想实现之前,Quora性能敏感的后端代码都是使用C++编写的。Charlie也补充说Django, Pylons等好的框架让他们获益颇多,Python 和 Javascript 的数据结构非常和谐,以及邮件服务,任务队列等优秀的第三方库。

引用出处:
Quora Infrastructure: Why did Quora choose Python for its development? 我记得有句话是这么说的:
一只木桶盛水的多少,并不取决于桶壁上最高的那块木块,而恰恰取决于桶壁上最短的那块
还有一句话是这么说的:
一条铁链的承重量是由它最脆弱的那一环决定的

对了,这里还有一个图,我觉得最恰当不过了:
为什么 Dropbox 等大型服务使用 Python 作为主要语言,即使它的效率比其他编译型语言低几个数量级?
结合上面大家的回答,题主应该明白了吧 现在大型系统很少用单纯一种语言写出来。。每种语言有每种语言的特色和适用环境。
企业会根据具体的使用环境(IO密集还是计算密集、开发效率等)来为不同的组件选择不同的语言。
对于那些对效率要求极高,但很少改动的地方用编译型语言。对开发效率要求极高,三天两头就要加入新功能的组件来说,上线所需的“时间成本”要比为了提升速度所需的“硬件投入”要值钱得多。
使用解释型语言的主要环境就是在“以(硬件占地)空间换(开发)时间”的一种经济的行为。。 对于这样逻辑相对简单,要求的是大并发量的网络运用,语言本身的性能影响并不显著,更多的瓶颈在于IO性能上,所以用什么语言区别并不是特别大,那么使用快速开发,快速迭代,快速部署的语言,比用C这样追求性能的语言,在开发效率和整体成本上更合适。 关键是IO速度慢 也就显不出python慢了 Dropbox这种客户端使用到的算法部分使用了C EXT,甚至其UI库wxwidget也是Python套的壳,速度瓶颈的地方都是C代码,所以还好。
至于服务器端,Dropbox的情况不太清楚,例如Quora已经全面转Cython以承受更大的负载,我想Dropbox服务器端也不可能纯Python来实现。 初期上线就是看谁更敏捷 曾经看过dropbox开发者的几篇博文。他们采用python的主要原因是可以比较简单的实现跨平台,而且开发速度快,进而实现快速上线的目的。 你可以用谷歌搜索一下dropbox的技术栈,会找到我说的博文的。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Merging Lists in Python: Choosing the Right MethodMerging Lists in Python: Choosing the Right MethodMay 14, 2025 am 12:11 AM

TomergelistsinPython,youcanusethe operator,extendmethod,listcomprehension,oritertools.chain,eachwithspecificadvantages:1)The operatorissimplebutlessefficientforlargelists;2)extendismemory-efficientbutmodifiestheoriginallist;3)listcomprehensionoffersf

How to concatenate two lists in python 3?How to concatenate two lists in python 3?May 14, 2025 am 12:09 AM

In Python 3, two lists can be connected through a variety of methods: 1) Use operator, which is suitable for small lists, but is inefficient for large lists; 2) Use extend method, which is suitable for large lists, with high memory efficiency, but will modify the original list; 3) Use * operator, which is suitable for merging multiple lists, without modifying the original list; 4) Use itertools.chain, which is suitable for large data sets, with high memory efficiency.

Python concatenate list stringsPython concatenate list stringsMay 14, 2025 am 12:08 AM

Using the join() method is the most efficient way to connect strings from lists in Python. 1) Use the join() method to be efficient and easy to read. 2) The cycle uses operators inefficiently for large lists. 3) The combination of list comprehension and join() is suitable for scenarios that require conversion. 4) The reduce() method is suitable for other types of reductions, but is inefficient for string concatenation. The complete sentence ends.

Python execution, what is that?Python execution, what is that?May 14, 2025 am 12:06 AM

PythonexecutionistheprocessoftransformingPythoncodeintoexecutableinstructions.1)Theinterpreterreadsthecode,convertingitintobytecode,whichthePythonVirtualMachine(PVM)executes.2)TheGlobalInterpreterLock(GIL)managesthreadexecution,potentiallylimitingmul

Python: what are the key featuresPython: what are the key featuresMay 14, 2025 am 12:02 AM

Key features of Python include: 1. The syntax is concise and easy to understand, suitable for beginners; 2. Dynamic type system, improving development speed; 3. Rich standard library, supporting multiple tasks; 4. Strong community and ecosystem, providing extensive support; 5. Interpretation, suitable for scripting and rapid prototyping; 6. Multi-paradigm support, suitable for various programming styles.

Python: compiler or Interpreter?Python: compiler or Interpreter?May 13, 2025 am 12:10 AM

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Python For Loop vs While Loop: When to Use Which?Python For Loop vs While Loop: When to Use Which?May 13, 2025 am 12:07 AM

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Python loops: The most common errorsPython loops: The most common errorsMay 13, 2025 am 12:07 AM

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool