df63692a18
Deploy Examination / deploy (push) Successful in 31s
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
164 lines
4.8 KiB
JSON
164 lines
4.8 KiB
JSON
{
|
|
"topic": "http-connection-cost",
|
|
"type": "fill_blank",
|
|
"schema_version": "1.0.0",
|
|
"generated": "2026-09-02T21:20:00+08:00",
|
|
"questions": [
|
|
{
|
|
"id": "fb-001",
|
|
"type": "fill_blank",
|
|
"difficulty": 2,
|
|
"tags": [
|
|
"TCP",
|
|
"内存"
|
|
],
|
|
"question": "操作系统为每个 TCP 连接分配的内核内存大约是____KB。",
|
|
"answer": [
|
|
"3-10"
|
|
],
|
|
"explanation": "操作系统为每个 TCP 连接分配的内核内存大约是 3-10 KB,包括发送/接收缓冲区和 TCP 控制块。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-002",
|
|
"type": "fill_blank",
|
|
"difficulty": 3,
|
|
"tags": [
|
|
"线程模型"
|
|
],
|
|
"question": "传统线程模型(Java BIO)每连接的内存消耗大约是____MB。",
|
|
"answer": [
|
|
"1"
|
|
],
|
|
"explanation": "传统线程模型每连接约 1 MB(主要是线程栈),协程模型(Go/async)仅需约 4 KB,异步事件驱动(Nginx)约 2 KB。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-003",
|
|
"type": "fill_blank",
|
|
"difficulty": 4,
|
|
"tags": [
|
|
"百万并发"
|
|
],
|
|
"question": "百万并发场景下,使用传统线程模型需要约____TB 内存,这在物理上不可行。",
|
|
"answer": [
|
|
"1"
|
|
],
|
|
"explanation": "传统线程模型每连接约 1 MB,百万并发需要约 1 TB 内存,这在物理上不可行。协程模型约 4 GB 是可行的。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-004",
|
|
"type": "fill_blank",
|
|
"difficulty": 2,
|
|
"tags": [
|
|
"TCP",
|
|
"端口"
|
|
],
|
|
"question": "客户端临时端口是____位整数,理论上限 65535。",
|
|
"answer": [
|
|
"16"
|
|
],
|
|
"explanation": "客户端端口是 16 位整数,理论上限 65535。每个 TCP 连接需要一个唯一的四元组。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-005",
|
|
"type": "fill_blank",
|
|
"difficulty": 3,
|
|
"tags": [
|
|
"Go",
|
|
"goroutine"
|
|
],
|
|
"question": "Go goroutine 的初始栈大小是____KB,可动态增长到 1 GB。",
|
|
"answer": [
|
|
"2"
|
|
],
|
|
"explanation": "Go goroutine 初始栈大小为 2 KB(可动态增长到 1 GB),Java 线程默认栈大小为 1 MB。相同内存下 Go 能创建的并发单元数量是 Java 的约 500 倍。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-006",
|
|
"type": "fill_blank",
|
|
"difficulty": 3,
|
|
"tags": [
|
|
"TLS",
|
|
"HTTPS"
|
|
],
|
|
"question": "HTTPS 场景下 TLS 会话缓存每个连接额外消耗____KB 内存。",
|
|
"answer": [
|
|
"50-100"
|
|
],
|
|
"explanation": "HTTPS 场景下 TLS 会话缓存每个连接额外消耗 50-100 KB 内存,百万并发下可能吃掉 50 GB 内存。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-007",
|
|
"type": "fill_blank",
|
|
"difficulty": 2,
|
|
"tags": [
|
|
"文件描述符"
|
|
],
|
|
"question": "每个 TCP 连接占____个文件描述符(fd)。",
|
|
"answer": [
|
|
"1"
|
|
],
|
|
"explanation": "每个 TCP 连接占 1 个文件描述符(fd),受系统 ulimit 限制。百万并发需要调大 ulimit 到至少 1048576。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-008",
|
|
"type": "fill_blank",
|
|
"difficulty": 4,
|
|
"tags": [
|
|
"异步模型"
|
|
],
|
|
"question": "异步事件驱动模型(如 Nginx)每连接的内存消耗大约是____KB。",
|
|
"answer": [
|
|
"2"
|
|
],
|
|
"explanation": "异步事件驱动模型(Nginx)每连接约 2 KB,几乎不占位置。这是最高效的连接模型,但编程复杂度最高。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-009",
|
|
"type": "fill_blank",
|
|
"difficulty": 3,
|
|
"tags": [
|
|
"Epoll",
|
|
"IO多路复用"
|
|
],
|
|
"question": "撑住百万并发的关键手段包括____/Kqueue(不为每个连接开线程)。",
|
|
"answer": [
|
|
"Epoll"
|
|
],
|
|
"explanation": "Epoll/Kqueue 是 IO 多路复用机制,不为每个连接开线程,一个线程就能监控百万文件描述符。",
|
|
"source": null,
|
|
"related": []
|
|
},
|
|
{
|
|
"id": "fb-010",
|
|
"type": "fill_blank",
|
|
"difficulty": 2,
|
|
"tags": [
|
|
"TCP",
|
|
"四元组"
|
|
],
|
|
"question": "TCP 连接的四元组包括源 IP、源端口、目标 IP 和目标____。",
|
|
"answer": [
|
|
"端口"
|
|
],
|
|
"explanation": "TCP 连接的四元组是:源 IP、源端口、目标 IP、目标端口。协议号(TCP=6)是固定的,不属于四元组。",
|
|
"source": null,
|
|
"related": []
|
|
}
|
|
]
|
|
} |