Python vs multiprocessing
summary
Python multiprocessing with large payloads uses OS shared_memory to avoid copying but requires explicit lifecycle control; a custom shared_memory wrapper is built that tracks ownership and can leak if not closed. Naive owner flags break when an object is sent to multiple workers; adding a per-block atomic reference counter (via a small C extension / atoms library) prevents premature frees and segmentation faults. Locked-manager dicts are safe but slow under load (tests up to ~800 RPS); atomics restore near-baseline latency.
AI-written summary · about
chapters (27)
- 0:00Introduction and speaker background
- 1:29Multiprocessing basics and motivation
- 4:38Parallel processing with ProcessPoolExecutor
- 6:28Shared memory and its benefits
- 7:32Memory leaks with shared memory
- 8:54SharedMemoryManager for safety
- 10:17Building a SharedMemoryWrapper
- 13:51Reference counting challenges
- 16:39Atomic operations and synchronization
- 21:57Atomic operations in practice
- 23:42Performance comparison and results
- 24:47Q&A session begins
- 25:37Handling process termination
- 27:05Signaling memory changes
- 28:13Comparison with Ray and alternatives
- 29:19GPU context and multiprocessing
- 31:28File system vs shared memory
- 33:14Shared memory limitations in Python
- 34:39Handling large data transfers
- 35:21Multiprocessing vs horizontal scaling
- 37:07Resource competition in virtual environments
- 38:10Atomic operations and memory safety
- 39:16Context manager trade-offs
- 40:21Comparison with Triton and TF serving
- 41:46Memory management in practice
- 43:32Code review and potential issues
- 44:59Final Q&A and closing
