知识卡片

普通读书笔记卡 · 10346.a.3.b · 生成模型:未记录

串行请求相互排队

理解等级:中级

接收线程同步执行 handle_connection 时,只有它返回后才能继续处理下一条连接。先处理耗时任务会推迟随后很短的任务。加入一个固定延迟的 /sleep 路径可在本地观察这种排队:先启动慢请求,才提交快请求;在顺序执行的版本中,快请求也必须等慢请求完成。

相关卡片 [[线程池限制并发任务]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第20章 最终项目:构建多线程 Web 服务器(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c20.xhtml`,块 0121) - 结论依据:原文描述了用两个窗口依次打开慢路径和快路径,观察后者也要等待的过程。 - 原始内容:Start the server using cargo run. Then open two browser windows: one for http://127.0.0.1:7878 and the other for http://127.0.0.1:7878/sleep. If you enter the / URI a few times, as before, you’ll see it respond quickly. But if you enter /sleep and then load /, you’ll see that / waits until sleep has slept for its full five seconds before loading.