A CPU bound job (pure computation, no I/O) runs on an 8 core machine. Which approach gives near linear speedup in a runtime without a global interpreter lock?
Show answer
Answer
About 8 workers (threads or processes), one per core
CPU bound work scales with cores, so one worker per core keeps every core busy with minimal switching. Hundreds of threads add switching and cache pressure with no extra cores to run on. An event loop runs on one core and only helps when tasks wait on I/O. Context switching costs little at 8 workers on 8 cores.
Source: IGotAnOffer: Anthropic software engineer interview, OSTEP: Concurrency: An Introduction