没有合适的资源?快使用搜索试试~ 我知道了~
首页The Hacker’s Guide to Scaling Python
资源详情
资源评论
资源推荐


The Hacker’s Guide to Scaling
Python
Julien Danjou
Julien Danjou
<julien@danjou.info>
Copyright © 2016-2017 Julien Danjou
Revision History
Revision 1.0 May 2017 JD
First Edition.
2

About this Book
Version 1.0 released in 2017.
When I released The Hacker’s Guide to Python in 2014, I had no
idea that I would be writing a new book so soon. Having worked on
OpenStack for a few more years, I saw how it is easy to struggle with
other aspects of Python, even after being on board for a while.
Nowadays, even if computers are super-fast, no server is fast
enough to handle millions of request per second, which is a typical
workload we want to use them for. Back in the day, when your
application was slow, you just had to optimize it or upgrade your
hardware – whichever was cheaper. However, in a world where you
may already have done both, you need to be able to scale your
application horizontally, i.e., you have to make it run on multiple
computers in parallel.
That is usually the start of a long journey, filled with concurrency
problems and disaster scenarios.
Developers often dismiss Python when they want to write
performance enhancing, and distributed applications. They tend to
consider the language to be slow and not suited to that task. Sure,
Python is not Erlang, but there’s also no need to ditch it for Go
because of everyone saying it is faster.
I would like to make you aware, dear reader, that a language is
never slow. You would not say that English or French is slow, right?
The same applies for programming languages. The only thing that
can be slow is the implementation of the language – in Python’s
case, its reference implementation is CPython.
Indeed CPython can be quite sluggish, and it has its share of
problems. Every implementation of a programming language has its
downside. However, I think that the ecosystem of Python can make
up for that defect.
3

Python and everything that evolves around it offer a large set of
possibilities to extend your application, so it can manage thousands
of requests simultaneously, compensating for its lack of distributed
design or, sometimes its "slowness".
Moreover, if you need proof, you can ask companies such as
Dropbox, PayPal or Google as they all use Python on a large scale.
Instagram has 400 million active users every day and their whole
stack is served using Python and Django.
In this book, we will discuss how one can push Python further and
build applications that can scale horizontally, perform well and
remain fast while being distributed. I hope it makes you more
productive at Python and allows you to write better applications
that are also faster!
Most code in this book targets Python 3. Some snippets might work
on Python 2 without much change, but there is no guarantee.
4

Chapter 1. Scaling?
Scalability is the capability of a system, network, or process to
handle a growing amount of work, or its potential to be enlarged
to accommodate that growth.
-- Wikipedia
When we talk about scaling Python, what we mean is making
Python application scalable. However, what is scalability?
According to Wikipedia, scalability is "the capability of a system,
network, or process to handle a growing amount of work, or its
potential to be enlarged to accommodate that growth". This
definition makes scalability difficult to define as an absolute since
no definition applies to all applications.
This book concentrates on methods, technologies, and practice that
allow one to make applications fast and able to grow in order to
handle more jobs – all of that using the Python programming
language and its major implementation, named CPython.
We are all aware that processors are not becoming faster and faster
at a rate where a single threaded application could, one day, be fast
enough to handle any size workload. That means you need to think
about using more than just one processor. Building scalable
applications implies that you distribute the workload across
multiple workers using multiple processing units.
Dividing up the tasks at hand, those workers run across several
processors, and in some cases, across several computers.
That is a distributed application.
There are fundamental properties to understand about distributed
systems before digging into how to build them in Python – or any
other language.
5
剩余287页未读,继续阅读















安全验证
文档复制为VIP权益,开通VIP直接复制

评论2