Files
wonder df63692a18
Deploy Examination / deploy (push) Successful in 31s
feat: add 180 questions (90 sc + 90 fb) for networking subtopics
Cover 9 subtopics from the computer networking documentation:
- http-handshake: TCP/TLS/HTTP2/HTTP3 handshakes
- http-connection-cost: connection resource overhead & million concurrency
- connection-pooling: pool reuse, HTTP/1.1 vs HTTP/2
- http-keepalive: Keep-Alive principle, head-of-line blocking
- keepalive-scenarios: when to enable/disable Keep-Alive
- domain-sharding: HTTP/1.1 hack, HTTP/2 obsolescence
- cdn: edge nodes, caching, DDoS protection
- cors: same-origin policy, preflight requests
- go-build-strip: -s -w flags, binary size optimization
2026-09-02 21:33:09 +08:00

209 lines
6.9 KiB
JSON

{
"topic": "connection-pooling",
"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": [
"连接池",
"基本概念"
],
"question": "连接池的核心思想是什么?",
"options": {
"A": "每次请求都新建连接",
"B": "预建一批连接,用时借出,用完归还而非关闭",
"C": "关闭所有空闲连接",
"D": "限制最大请求并发数"
},
"answer": "B",
"explanation": "连接池是一批预先建好的连接集合,用时借出,用完归还而非关闭。高频场景下最简单有效的优化,避免了每次请求都要建 TCP 连接和 TLS 握手的开销。",
"source": null,
"related": []
},
{
"id": "sc-002",
"type": "single_choice",
"difficulty": 3,
"tags": [
"HTTP/1.1",
"Keep-Alive",
"队头阻塞"
],
"question": "HTTP/1.1 的 Keep-Alive 复用存在什么限制?",
"options": {
"A": "不能复用连接",
"B": "同一时刻只能有一个请求在跑(队头阻塞)",
"C": "最多复用 3 个请求",
"D": "需要额外付费"
},
"answer": "B",
"explanation": "HTTP/1.1 的 Keep-Alive 复用虽然解决了频繁握手问题,但同一时刻只能有一个请求在跑(队头阻塞)。浏览器默认开 6 个连接来弥补。",
"source": null,
"related": []
},
{
"id": "sc-003",
"type": "single_choice",
"difficulty": 3,
"tags": [
"HTTP/2",
"多路复用"
],
"question": "HTTP/2 的多路复用如何处理多个请求?",
"options": {
"A": "每个请求一个 TCP 连接",
"B": "一个 TCP 连接上并行处理多个请求/响应,通过帧编号区分",
"C": "串行处理所有请求",
"D": "使用 UDP 协议"
},
"answer": "B",
"explanation": "HTTP/2 的多路复用在一个 TCP 连接上同时跑多个请求/响应,通过帧编号区分。不再需要多个 TCP 连接来并行,一根连接全部搞定。",
"source": null,
"related": []
},
{
"id": "sc-004",
"type": "single_choice",
"difficulty": 4,
"tags": [
"连接池",
"配置"
],
"question": "连接池最大连接数设得过大可能导致什么问题?",
"options": {
"A": "请求处理速度变慢",
"B": "内存和文件描述符浪费",
"C": "连接加密失败",
"D": "DNS 解析变慢"
},
"answer": "B",
"explanation": "连接池最大连接数过大,每个连接都占内存和 fd,导致资源浪费。应该根据服务端能承受的并发数和实际需求合理配置。",
"source": null,
"related": []
},
{
"id": "sc-005",
"type": "single_choice",
"difficulty": 3,
"tags": [
"僵尸连接",
"健康检查"
],
"question": "连接池中的僵尸连接是什么?",
"options": {
"A": "正在使用的连接",
"B": "服务器端已关闭但客户端不知道,下次复用时发现连接已死",
"C": "加密失败的连接",
"D": "超时的连接"
},
"answer": "B",
"explanation": "僵尸连接是指服务器端已经关闭了连接,但客户端不知道,下次复用时发现连接已死。解决方案:开启连接健康检查、设置合理的空闲超时、使用 TCP keepalive。",
"source": null,
"related": []
},
{
"id": "sc-006",
"type": "single_choice",
"difficulty": 2,
"tags": [
"连接池",
"Python"
],
"question": "Python requests 库中,pool_maxsize 参数控制什么?",
"options": {
"A": "最大请求数",
"B": "每个池子最多保持的连接数",
"C": "请求超时时间",
"D": "重试次数"
},
"answer": "B",
"explanation": "pool_maxsize 控制每个池子最多保持的连接数。pool_connections 是连接到不同目标服务器的池子数。",
"source": null,
"related": []
},
{
"id": "sc-007",
"type": "single_choice",
"difficulty": 4,
"tags": [
"连接池",
"HTTP/2"
],
"question": "HTTP/2 的多路复用还需要连接池吗?",
"options": {
"A": "完全不需要",
"B": "仍然需要,连接池提供容错和负载均衡能力",
"C": "只需要 1 个连接",
"D": "连接池会干扰多路复用"
},
"answer": "B",
"explanation": "连接池仍然有用。HTTP/2 解决了单个连接上的并行问题,但连接池提供了容错(一个连接挂了可以切到另一个)和负载均衡(多连接分散压力)的能力。",
"source": null,
"related": []
},
{
"id": "sc-008",
"type": "single_choice",
"difficulty": 2,
"tags": [
"连接池",
"Go"
],
"question": "Go 的 http.Transport 中 MaxIdleConnsPerHost 参数控制什么?",
"options": {
"A": "最大空闲连接总数",
"B": "每个主机最多保留的空闲连接数",
"C": "连接超时时间",
"D": "最大并发请求数"
},
"answer": "B",
"explanation": "MaxIdleConnsPerHost 控制每个主机最多保留的空闲连接数。MaxIdleConns 是最大空闲连接总数,IdleConnTimeout 是空闲连接超时时间。",
"source": null,
"related": []
},
{
"id": "sc-009",
"type": "single_choice",
"difficulty": 3,
"tags": [
"连接池",
"延迟"
],
"question": "连接池打满时会发生什么?",
"options": {
"A": "自动扩容",
"B": "新请求排队等连接,延迟飙升",
"C": "直接拒绝请求",
"D": "自动建立新连接"
},
"answer": "B",
"explanation": "连接池打满时,新请求需要排队等连接归还,导致延迟飙升。解决方案:合理调大池子,或用 HTTP/2 多路复用减少对连接数的需求。",
"source": null,
"related": []
},
{
"id": "sc-010",
"type": "single_choice",
"difficulty": 4,
"tags": [
"连接池",
"Java"
],
"question": "Java Apache HttpClient 中 setDefaultMaxPerRoute(20) 的含义是?",
"options": {
"A": "总连接池大小为 20",
"B": "每个目标服务器最多 20 个连接",
"C": "最大空闲连接为 20",
"D": "连接超时 20 秒"
},
"answer": "B",
"explanation": "setDefaultMaxPerRoute(20) 表示每个目标服务器(路由)最多 20 个连接。setMaxTotal(200) 才是总连接池大小。",
"source": null,
"related": []
}
]
}