知识卡片
线程池限制并发任务
线程池预先启动 N 个工作线程,让相同线程反复从队列取任务,活动任务数量最多为 N。相比逐请求创建线程,这限制了工作线程占用。某个请求变慢时还有其他空闲工作线程可用。全部线程繁忙后,队列仍然会积压,线程数量限制与队列容量是两个控制点。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 最终项目:构建多线程 Web 服务器 Improving Throughput with a Thread Pool · 查看原书依据
Rather than spawning unlimited threads, then, we’ll have a fixed number of threads waiting in the pool. Requests that come in are sent to the pool for processing. The pool will maintain a queue of incoming requests. Each of the threads in the pool will pop off a request from this queue, handle the request, and then ask the queue for another request.
参考来源
- 位置:《The Rust Programming Language(第2版)》第20章 最终项目:构建多线程 Web 服务器(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c20.xhtml`,块 0126)
- 结论依据:原文说明固定工作线程、排队取活及全员忙碌后请求仍会积压。
- 原始内容:Rather than spawning unlimited threads, then, we’ll have a fixed number of threads waiting in the pool. Requests that come in are sent to the pool for processing. The pool will maintain a queue of incoming requests. Each of the threads in the pool will pop off a request from this queue, handle the request, and then ask the queue for another request.