Out of the Frying Pan/Into the Fire -Multiprocessed code to Free Threading
summary
Converts multiprocessing to free-threading on an 80-core Linux server using a CPU-heavy loop (2,500 ops per iteration) and benchmarks at 5k/50k/500k tasks, finds free-threading fastest only at small scale then slower as contention and cache effects appear, shares a 2 million-integer list to reveal copy-on-write advantages for multiprocessing, observes a race that produces ~1% counter loss, and only beats multiprocessing after adding locks, using FTUtils local wrapper and atomic_int64, but notes free-threading remains experimental.
AI-written summary · about
chapters (20)
- 0:00Introduction to free threading
- 0:50Concurrency options overview
- 2:36Global Interpreter Lock explained
- 4:02Challenges with traditional threading
- 5:48Multiprocessing limitations
- 8:19Free threading advantages
- 9:22Benchmark setup and machine specs
- 10:27CPU-bound code performance comparison
- 12:10Shared data read-only benchmark
- 14:15Shared data read-write benchmark
- 15:43Unbalanced workload impact
- 16:47Thread contention and cache issues
- 18:33Reference count contention
- 20:21Race conditions in threading
- 22:06Optimizing with locks
- 22:48FTUtils library introduction
- 24:35Final performance results
- 25:38Thread sanitizer for Python
- 26:43When to use free threading
- 27:49Q&A session
