Skip to content

Commit 28d8ac0

Browse files
More explanation.
1 parent fce455e commit 28d8ac0

File tree

1 file changed

+91
-21
lines changed

1 file changed

+91
-21
lines changed

Doc/howto/concurrency.rst

+91-21
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ look in Python, with an emphasis on practical workload-oriented examples.
1111

1212
The following Python concurrency models are covered:
1313

14-
* threads (:mod:`threading` and :mod:`concurrent.futures`)
14+
* free-threading (:mod:`threading` and :mod:`concurrent.futures`)
15+
* isolated threads, AKA CSP/actor model (:mod:`!interpreters`)
1516
* multi-processing (:mod:`multiprocessing` and :mod:`concurrent.futures`)
16-
* async/await
17-
* CSP/actor model (:mod:`!interpreters`)
18-
* distributed (e.g. SMP)
17+
* distributed, e.g. SMP (:mod:`!dask`)
18+
* async/await (:mod:`asycio`)
1919

2020
Each of these will be explained, with some simple examples. The later
2121
workload-oriented examples will be implemented using each,
@@ -127,13 +127,15 @@ of well defined abstract models, with different characteristics and
127127
tradeoffs. The application of the different theoretical concurrency
128128
models can be categorized as follows:
129129

130-
* free threads - using multiple physical threads in the same process,
131-
with no isolation between them
132-
* isolated threads - threads, often physical, with strict isolation
133-
between them (e.g. CSP and actor model)
134-
* multiprocessing - using multiple isolated processes
135-
* distributed - multiprocessing across multiple computers
136-
* async/await - using coroutines (AKA "cooperative multitasking")
130+
================= ==========
131+
free threads using multiple physical threads in the same process,
132+
with no isolation between them
133+
isolated threads threads, often physical, with strict isolation
134+
between them (e.g. CSP and actor model)
135+
multiprocessing using multiple isolated processes
136+
distributed multiprocessing across multiple computers
137+
async/await using coroutines (AKA "cooperative multitasking")
138+
================= ==========
137139

138140
(There are certainly others, but these are the focus here.)
139141

@@ -214,10 +216,67 @@ was registered.
214216
Workloads
215217
---------
216218

217-
We've looked at what you can do with concurrency from a high level.
218-
Now let's look at some concrete examples.
219-
220-
...
219+
In practice, concurrency is used in a wide variety of software.
220+
Here's a not-comprehensive list:
221+
222+
======================= ===========
223+
application concurrency
224+
======================= ===========
225+
web server handle simultaneous static requests, CGI requests
226+
web browser load multiple resources at once
227+
database server handle simultaneous requests
228+
devops script process multiple files at once
229+
system logger handle simultaneous logging requests
230+
ATM network handle multiple bank transactions at once
231+
hacker toolkit decode a passwd file with brute force
232+
raytracer compute RGB for each image pixel
233+
machine learning apply matrices on training data set
234+
astrophysics merge black hole data from multiple satelites and observatories
235+
investing combine thousands of industry data sources into a concise actionable analysis
236+
MMO game server handle login requests, handle client updates
237+
game client GUI, physics engine, handle server updates
238+
audio transcoder process chunks
239+
engineering simultation calculate stress loads at vertices
240+
molecular modeling try many permutations
241+
======================= ===========
242+
243+
It can be helpful to identify common characteristics by which we could
244+
group concurrency workloads. Here are some:
245+
246+
* number of logical threads
247+
* main + workers vs. independent
248+
* main + background
249+
* how much computation, per thread
250+
* how much blocking on other threads, per thread
251+
* how much blocking IO, per thread
252+
* number of external inputs
253+
* number of external outputs
254+
* how much data used, per thread
255+
* how much data do logical threads share
256+
* size of the data shared by threads
257+
258+
From our list of workloads above, we can observe some clustering:
259+
260+
* ...
261+
262+
Let's also revisit the ways concurrency can be helpful:
263+
264+
* get work done faster
265+
* run more tasks at once (multi-core)
266+
* make the app feel more responsive
267+
* make sure critical tasks have priority
268+
* process results as they come, instead of waiting for them all
269+
* send payload to multiple targets before starting next task
270+
* use system resources more efficiently
271+
* keep slow parts from blocking fast parts
272+
* keep blocking resources from blocking the whole program
273+
* make sure other tasks have a fair share of time
274+
* task scheduling & resource usage optimization
275+
* scaling
276+
* handle asynchronous events
277+
278+
All of these things factor in to how concurrency should be applied for
279+
a workload, or even if it should.
221280

222281

223282
Python Concurrency Models
@@ -233,30 +292,41 @@ The stdlib :mod:`threading` module ...
233292

234293
...
235294

295+
Isolated Threads (CSP/Actor Model)
296+
----------------------------------
297+
298+
The future stdlib :mod:`!interpreters` module ...
299+
300+
...
301+
236302
Multi-processing
237303
----------------
238304

305+
The stdlib :mod:`multiprocessing` module ...
306+
239307
...
240308

241-
Async/Await
309+
Distributed
242310
-----------
243311

244-
...
245-
246-
Isolated Threads (CSP/Actor Model)
247-
----------------------------------
312+
The popular :mod:`!dask` module ...
248313

249314
...
250315

251-
Distributed
316+
Async/Await
252317
-----------
253318

319+
The stdlib :mod:`asyncio` module ...
320+
254321
...
255322

256323

257324
Python Concurrency Workloads
258325
============================
259326

327+
Below we have a series of examples of how to implement the most
328+
common Python workloads that take advantage of concurrency.
329+
260330
...
261331

262332
also see:

0 commit comments

Comments
 (0)