Pick the fix
A request handler resizes images in pure Python and takes 800 ms of CPU. Throughput is poor under a thread pool. Best change?
Hint 1 of 1
Is the work waiting or computing?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Run the resize in a process pool or a background worker, or use a library that releases the GIL
Correct. CPU work needs real parallelism outside one interpreter lock.
In standard CPython only one thread runs Python bytecode at a time, so CPU-bound threads take turns. Separate processes each have their own interpreter and GIL and can use several cores.
Why not the others?
- B Increase the thread pool to 64. More threads still share one GIL for Python bytecode.
- C Convert the handler to async. async doesn't make CPU work parallel.
- D Add caching headers. Doesn't change the CPU cost of new images.