{ "topic": "http-keepalive", "type": "single_choice", "schema_version": "1.0.0", "generated": "2026-09-02T21:20:00+08:00", "questions": [ { "id": "sc-001", "type": "single_choice", "difficulty": 2, "tags": [ "Keep-Alive", "HTTP/1.1" ], "question": "HTTP/1.1 默认是否启用 Keep-Alive?", "options": { "A": "默认不启用", "B": "默认启用", "C": "需要手动配置", "D": "仅 HTTPS 启用" }, "answer": "B", "explanation": "HTTP/1.1 默认启用 Keep-Alive,建一次连接后可以连续发多个请求,不用每次重新握手。这是 HTTP/1.1 最重要的默认优化。", "source": null, "related": [] }, { "id": "sc-002", "type": "single_choice", "difficulty": 3, "tags": [ "Keep-Alive", "Connection头" ], "question": "服务器通过哪个响应头告诉客户端连接可以复用?", "options": { "A": "Connection: close", "B": "Connection: Keep-Alive", "C": "Keep-Alive: true", "D": "Reuse: true" }, "answer": "B", "explanation": "服务器通过 Connection: Keep-Alive 响应头告诉客户端这个连接可以复用。Connection: close 表示不要复用。", "source": null, "related": [] }, { "id": "sc-003", "type": "single_choice", "difficulty": 3, "tags": [ "Keep-Alive", "timeout", "max" ], "question": "Keep-Alive: timeout=5, max=100 中 max=100 的含义是?", "options": { "A": "最大并发连接数为 100", "B": "空闲超时 100 秒", "C": "单连接最多处理 100 个请求后强制关闭", "D": "最大响应大小 100KB" }, "answer": "C", "explanation": "max=100 表示单连接最多处理 100 个请求后强制关闭。timeout=5 表示空闲超过 5 秒没新请求就关闭连接。两者取先触发的那个。", "source": null, "related": [] }, { "id": "sc-004", "type": "single_choice", "difficulty": 3, "tags": [ "队头阻塞", "HTTP/1.1" ], "question": "Keep-Alive 引入了什么问题?", "options": { "A": "带宽不足", "B": "队头阻塞", "C": "DNS 解析慢", "D": "TLS 握手失败" }, "answer": "B", "explanation": "Keep-Alive 解决了频繁握手问题,但引入了队头阻塞——同一连接上的请求严格串行,后一个请求必须等前一个响应返回。浏览器用多开 6 个连接来弥补。", "source": null, "related": [] }, { "id": "sc-005", "type": "single_choice", "difficulty": 4, "tags": [ "HTTP/1.1", "浏览器", "6连接" ], "question": "HTTP/1.1 的 Keep-Alive 存在队头阻塞,浏览器用什么方式弥补?", "options": { "A": "使用 HTTP/2", "B": "同时开 6 个 TCP 连接", "C": "使用 UDP 协议", "D": "增大窗口大小" }, "answer": "B", "explanation": "浏览器同时开 6 个 TCP 连接来弥补 HTTP/1.1 的队头阻塞问题——一条收银通道排队太慢,所以超市开了 6 个收银台,但每个收银台内部还是串行的。", "source": null, "related": [] }, { "id": "sc-006", "type": "single_choice", "difficulty": 2, "tags": [ "Keep-Alive", "HTTP/1.0" ], "question": "HTTP/1.0 的连接模型是怎样的?", "options": { "A": "一个连接串行多个请求", "B": "一个请求一个连接,用完即弃", "C": "一个连接并行多个请求", "D": "使用 UDP 协议" }, "answer": "B", "explanation": "HTTP/1.0 没有 Keep-Alive,一个请求一个连接,用完即弃。每个资源都要走一遍握手流程,光握手就比传数据花的时间还多。", "source": null, "related": [] }, { "id": "sc-007", "type": "single_choice", "difficulty": 4, "tags": [ "Keep-Alive", "空闲连接" ], "question": "Keep-Alive 连接在空闲时会占用什么资源?", "options": { "A": "只占用 CPU", "B": "占用内存和文件描述符", "C": "不占用任何资源", "D": "只占用网络带宽" }, "answer": "B", "explanation": "Keep-Alive 连接在空闲时仍然占内存和 fd。如果客户端长时间不发新请求,服务器应该主动关闭。合理设置 timeout 参数很重要。", "source": null, "related": [] }, { "id": "sc-008", "type": "single_choice", "difficulty": 3, "tags": [ "Keep-Alive", "演进" ], "question": "HTTP 连接复用的演进路线正确的是?", "options": { "A": "Keep-Alive → HTTP/1.0 → HTTP/2", "B": "无 Keep-Alive → Keep-Alive → HTTP/2 多路复用 → HTTP/3 QUIC", "C": "HTTP/2 → Keep-Alive → HTTP/3", "D": "TCP → UDP → HTTP/3" }, "answer": "B", "explanation": "演进路线:HTTP/1.0 无 Keep-Alive → HTTP/1.1 默认 Keep-Alive → 浏览器并行连接缓解队头阻塞 → HTTP/2 多路复用 → HTTP/3 QUIC 基于 UDP 的多路复用。", "source": null, "related": [] }, { "id": "sc-009", "type": "single_choice", "difficulty": 2, "tags": [ "Keep-Alive", "Connection头" ], "question": "不想复用连接时,服务器应该返回什么头?", "options": { "A": "Connection: Keep-Alive", "B": "Connection: close", "C": "Keep-Alive: false", "D": "Connection: none" }, "answer": "B", "explanation": "不想复用连接时,服务器返回 Connection: close,告诉客户端处理完当前请求后关闭连接。", "source": null, "related": [] }, { "id": "sc-010", "type": "single_choice", "difficulty": 3, "tags": [ "Keep-Alive", "服务器" ], "question": "服务器因超时关闭了连接,但客户端下次复用时才发现连接已死,这种情况应该怎么处理?", "options": { "A": "忽略错误", "B": "开启连接健康检查或设置合理的超时", "C": "增大连接池", "D": "使用 HTTP/1.0" }, "answer": "B", "explanation": "服务器因超时关闭了连接,但客户端不知道,下次复用时才发现连接已死。需要开启连接健康检查或设置合理的超时来避免这个问题。", "source": null, "related": [] } ] }