Repository navigation
Conversation
打开文献库或阅读页时浏览器一次请求几十个脚本和样式。ThreadingHTTPServer 默认 listen 队列只有 5,排不下的连接在 Linux 上被丢掉,要等一秒后重连; 放在反向代理后面时最明显。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
launch.py的_Server加一行request_queue_size = 64,另补一个测试tests/server/test_listen_backlog.py。为什么
打开文献库要请求约 60 个脚本和样式,阅读页约 90 个,浏览器会同时发出去。
ThreadingHTTPServer继承socketserver的默认值,listen()队列只有 5 个。服务线程还没accept时,排不下的连接在 Linux 上会被直接丢掉,客户端要等一秒才重试 SYN,所以有些请求凭空多出 1 秒以上。本机用浏览器直连时不常碰到。放在 Docker 或反向代理(Caddy、nginx)后面就很明显:代理会同时开很多条连接去连后端。
怎么复现
在 Linux(
python:3.12-slim容器)里,对一个ThreadingHTTPServer同时发 60 个请求:实际部署在反向代理后面时,同时发 12 个请求,有几个要 1.3 秒,其余约 0.25 秒。
测试
新测试先建好服务但不
accept,一次开 32 条非阻塞连接,要求 0.5 秒内全部连上。在 Linux 上,改动前只连上 6 条(6 != 32),改动后通过。tests.server.test_presence也照常通过。🤖 Generated with Claude Code