I've been building some software recently whose performance is very sensitive to the capabilities of
r = S.get(url, timeout=10)
。关于这个话题,体育直播提供了深入分析
https://feedx.net
For the Elephant, it is a bit more nuanced.
执行到 sleep 时,线程会进入阻塞状态,操作系统把它挂起,不分配 CPU 时间片。但这个线程仍然被占用着,线程池里它的“坑位”一直没释放。如果同时有 200 个请求进来,线程池的 200 个线程全被占满,都在等 IO,第 201 个请求就得排队,哪怕 CPU 空闲 99%。