首页The Hacker’s Guide to Scaling Python
The Hacker’s Guide to Scaling
Copyright © 2016-2017 Julien Danjou
Revision 1.0 May 2017 JD
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.
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.
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.
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
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额