@@ -11,11 +11,11 @@ look in Python, with an emphasis on practical workload-oriented examples.
11
11
12
12
The following Python concurrency models are covered:
13
13
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 `)
15
16
* 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 `)
19
19
20
20
Each of these will be explained, with some simple examples. The later
21
21
workload-oriented examples will be implemented using each,
@@ -127,13 +127,15 @@ of well defined abstract models, with different characteristics and
127
127
tradeoffs. The application of the different theoretical concurrency
128
128
models can be categorized as follows:
129
129
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
+ ================= ==========
137
139
138
140
(There are certainly others, but these are the focus here.)
139
141
@@ -214,10 +216,67 @@ was registered.
214
216
Workloads
215
217
---------
216
218
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.
221
280
222
281
223
282
Python Concurrency Models
@@ -233,30 +292,41 @@ The stdlib :mod:`threading` module ...
233
292
234
293
...
235
294
295
+ Isolated Threads (CSP/Actor Model)
296
+ ----------------------------------
297
+
298
+ The future stdlib :mod: `!interpreters ` module ...
299
+
300
+ ...
301
+
236
302
Multi-processing
237
303
----------------
238
304
305
+ The stdlib :mod: `multiprocessing ` module ...
306
+
239
307
...
240
308
241
- Async/Await
309
+ Distributed
242
310
-----------
243
311
244
- ...
245
-
246
- Isolated Threads (CSP/Actor Model)
247
- ----------------------------------
312
+ The popular :mod: `!dask ` module ...
248
313
249
314
...
250
315
251
- Distributed
316
+ Async/Await
252
317
-----------
253
318
319
+ The stdlib :mod: `asyncio ` module ...
320
+
254
321
...
255
322
256
323
257
324
Python Concurrency Workloads
258
325
============================
259
326
327
+ Below we have a series of examples of how to implement the most
328
+ common Python workloads that take advantage of concurrency.
329
+
260
330
...
261
331
262
332
also see:
0 commit comments