• Complain

Danjou - The Hackers Guide to Scaling Python

Here you can read online Danjou - The Hackers Guide to Scaling Python full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Danjou The Hackers Guide to Scaling Python
  • Book:
    The Hackers Guide to Scaling Python
  • Author:
  • Genre:
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

The Hackers Guide to Scaling Python: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "The Hackers Guide to Scaling Python" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Danjou: author's other books


Who wrote The Hackers Guide to Scaling Python? Find out the surname, the name of the author of the book and a list of all author's works by series.

The Hackers Guide to Scaling Python — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "The Hackers Guide to Scaling Python" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
The Hackers Guide to Scaling Python
Julien Danjou
Julien Danjou

Copyright 2016-2017 Julien Danjou

Revision History
Revision 1.0May 2017JD
First Edition.

About this Book

Version 1.0 released in 2017.

When I released The Hackers Guide toPython 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 sawhow it is easy to struggle with other aspects of Python, even after being onboard for a while.

Nowadays, even if computers are super-fast, no server is fast enough to handlemillions of request per second, which is a typical workload we want to use themfor. Back in the day, when your application was slow, you just had to optimizeit or upgrade your hardware whichever was cheaper. However, in a world whereyou may already have done both, you need to be able to scale your applicationhorizontally, 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 problemsand 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 andnot suited to that task. Sure, Python is not Erlang,but theres also no need to ditch it for Go because ofeveryone saying it is faster.

I would like to make you aware, dear reader, that a language is never slow. Youwould not say that English or French is slow, right? The same applies forprogramming languages. The only thing that can be slow is the implementation ofthe language in Pythons case, its reference implementation is CPython.

Indeed CPython can be quite sluggish, and it has its share of problems. Everyimplementation of a programming language has its downside. However, I thinkthat the ecosystem of Python can make up for that defect.

Python and everything that evolves around it offer a large set of possibilitiesto extend your application, so it can manage thousands of requestssimultaneously, compensating for its lack of distributed design or, sometimesits "slowness".

Moreover, if you need proof, you can ask companies such as Dropbox, PayPal orGoogle as they all use Python on a large scale. Instagram has 400 millionactive users every day andtheir whole stackis served using Python and Django.

In this book, we will discuss how one can push Python further and buildapplications that can scale horizontally, perform well and remain fast whilebeing distributed. I hope it makes you more productive at Python and allows youto write better applications that are also faster!

Most code in this book targets Python 3. Some snippets might work on Python 2without much change, but there is no guarantee.

Chapter 1. Scaling?

Scalability is the capability of a system, network, or process to handle agrowing amount of work, or its potential to be enlarged to accommodate thatgrowth.

-- Wikipedia

When we talk about scaling Python, what we mean is making Python applicationscalable. However, what is scalability?

According to Wikipedia, scalabilityis "the capability of a system, network, or process to handle a growing amountof work, or its potential to be enlarged to accommodate that growth". Thisdefinition makes scalability difficult to define as an absolute since nodefinition applies to all applications.

This book concentrates on methods, technologies, and practice that allow one tomake applications fast and able to grow in order to handle more jobs all ofthat using the Python programming language and its major implementation, namedCPython.

We are all aware that processors are not becoming faster and faster at a ratewhere a single threaded application could, one day, be fast enough to handleany size workload. That means you need to think about using more than just oneprocessor. Building scalable applications implies that you distribute theworkload across multiple workers using multiple processing units.

Dividing up the tasks at hand, those workers run across several processors, andin some cases, across several computers.

That is a distributed application .

There are fundamental properties to understand about distributed systems beforedigging into how to build them in Python or any other language.

We can lay out the following options when writing an application:

  • Write a single-threaded application. This should be your first pick, and indeed it implies no distribution. They are the simplest of all applications. They are easy to understand and therefore easier to maintain. However, they are limited by the power of using a single processor.
  • Write a multi-threaded application. Most computers even your smartphone are now equipped with multiple processing units. If an application can overload an entire CPUs, it needs to spread its workload over other processors by spawning new threads (or new processes). Multi-threading applications are more error-prone than single-threaded applications, but they offer fewer failure scenarios than multi-nodes applications, as no network is involved.
  • Write network distributed applications. This is your last resort when your application needs to scale significantly, and not even one big computer with plenty of CPUs is enough. Those are the most complicated applications to write as they use a network. It means they should handle a lot of scenarios, such as a total or partial failure of a node or the network, high latency, messages being lost, and any other terrible property related to the unreliability of networks.

The properties of distribution vary widely depending on the type you pick.Operations on a single processor can be regarded as fast, with low latencywhile being reliable, and ordered, whereas operations across several nodesshould be considered, slow, with high latency. They are often unreliable andunordered.

Consider each architecture choice or change carefully. As seen throughout thisbook, there are various tools and methods in Python available for dealing withany of those choices. They help to build distributed systems, and thereforescalable applications.

1.1. Across CPUs

Scaling across processors is usually done using multithreading. Multithreadingis the ability to run code in parallel using threads . Threads are usuallyprovided by the operating system and are contained in a single process. Theoperating system is responsible to schedule their execution.

Since they run in parallel, that means they can be executed on separateprocessors even if they are contained in a single process. However, if only oneCPU is available, the code is split up and run sequentially.

Therefore, when writing a multithreaded application, the code always runsconcurrently but runs in parallel only if there is more than one CPU available.

This means that multithreading looks like a good way to scale and parallelizeyour application on one computer. When you want to spread the workload, youstart a new thread for each new request instead of handling them one at a time.

However, this does have several drawbacks in Python. If you have been in thePython world for a long time, you have probably encountered the word GIL , andknow how hated it is. The GIL is the Python global interpreter lock , a lockthat must be acquired each time CPython needs to execute byte-code.Unfortunately, this means that if you try to scale your application by makingit run multiple threads, this global lock always limits the performance of yourcode, as there are many conflicting demands. All your threads try to grab it assoon as they need to execute Python instructions.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «The Hackers Guide to Scaling Python»

Look at similar books to The Hackers Guide to Scaling Python. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «The Hackers Guide to Scaling Python»

Discussion, reviews of the book The Hackers Guide to Scaling Python and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.