2.5 KiB
2.5 KiB
Day 1 — GIL + CPU-bound vs I/O-bound threading
Goals (what "done" means)
- I can explain the GIL in 2–3 sentences and why it impacts CPU-bound threading more than I/O-bound threading.
- I can choose between threads, processes, and asyncio for a given workload and justify it.
- I have benchmark results (numbers) that demonstrate the above.
Reading (mostly)
- Read: What Is the Python Global Interpreter Lock (GIL)? (Real Python)
- Write 5 bullets: what the GIL is, what it is not, and why it exists.
- Read: Understanding the Python GIL (PDF)
- Write 5 bullets: where threads do help, where they don’t, and what "switch interval" means (high level).
- Skim (reference): concurrent.futures — Python docs
- Note the difference between
ThreadPoolExecutorvsProcessPoolExecutor.
- Note the difference between
Hands-on (benchmark + notes)
- Create a benchmark script that compares these variants for a CPU-bound function:
- Serial (single process, no threads)
ThreadPoolExecutorProcessPoolExecutor
- Use a repeatable timing method (pick one):
timeit(preferred for small benchmarks): timeit — Python docs- or wall-clock timing with
time.perf_counter()(fine for longer tasks)
- Record results in a small table (example format):
- workload size parameters (so you can reproduce)
- runtime for each approach
- notes on CPU utilization / behavior
- Add an I/O-bound comparison:
- Serial loop calling
time.sleep(x) - Thread pool version (expect improvement)
- Serial loop calling
- Write "Conclusions" (minimum 6 sentences):
- What happened for CPU-bound?
- What happened for I/O-bound?
- What I would choose in real systems and why
Stretch (optional)
- Skim: PEP 703 – Making the Global Interpreter Lock Optional in CPython
- Write 3 bullets: what changes, tradeoffs, and why it matters.
Deliverables (to commit)
notes.mdupdated with:- explanation bullets
- benchmark table
- conclusions
benchmark.py(or similar) added with instructions to run
Suggested commits
day01: add GIL notes + benchmark scaffoldingday01: record CPU vs IO benchmark results and conclusions