-
Notifications
You must be signed in to change notification settings - Fork 2
/
TODO
75 lines (64 loc) · 2.96 KB
/
TODO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
* 性能分析, 改进锁的实现
* 实现 poll 和 epoll 并对比性能测试
* url 和 referer 的长度限制
* optimize performance from allocing memory by pool
* 采用 LRU 结构,分块缓存
* 文件读取优化, sendfile
* 优化程序阅读《computer system》中第五章「优化程序性能」
* support IPv6
* 对于 force 请求性能不正常
* 虚拟内存占用过高 20T
* _GNU_SOURCE 在文件内指定无效
已经完成
--------
+ 支持 FastCGI 和 chunked 回应
+ 实现配置文件解析和加载
+ 不实现 chunked 模式下的上传到 FastCGI,但是 content_length 的上传支持
+ 实现 HTTP/1.0 的特征
+ 实现 HTTP/1.1 的部分特征
+ Range 属于 HTTP/1.1,已经实现
+ Etag 和 If-None-Match 和 Cache-Control
+ 支持 If-Modified-Since 和 304
+ 支持 LINK UNLINK 等正确响应 Not Implement 并且 POST 405 Method Not Allowed (http/1.1)
+ 绑定 CPU 提高了 200000 pages/min,但是多工作进程没有提高多少效率
+ Trailer 允许在回应后部添加额外的 Header Field
+ linux 下 semaphore 文件存储于 /dev/shm/sem.xxx
+ 考虑超时节点的插入,来确定选取什么结构
添加请求超时是有序的,采用 lru 结构!
测试项目
--------
1. GET 请求 404 页面
2. GET 请求正常页面
3. HEAD 请求 404 页面
4. HEAD 请求正常页面
5. GET 请求正常页面回应 304 缓存
6. 分段下载
7. 超时
8. 连接在正常请求两个页面的重用
9. 连接在 404 响应后的重用
阅读源码需要关注的问题
----------------------
1. 超时处理
2. free 和 重用 request 问题
3. 是否时事件驱动
4. 解析 HTTP 如何与事件循环结合
5. post 之类请求如何处理,request 的后续 body 如何处理
etc
已经大体阅读
------------
1. boa server
其采用类似于事件驱动来做,维护 request 链,解析处理 HTTP 通过内部状态机,没有高级特性
根据发送完毕来决定 free_request,其中通过请求的信息来判断是否时真的销毁这个 request,并且还有超时处理
2. lighttpd
采用 server 这个结构体存储配置信息,对每个 connection 构建一个状态机,连接的处理也是在状态机里
3. nginx
采用 xxx_config 存储配置信息,主题结构维护在 cycle 里
事件循环
ngx_process_events_and_timers 处理事件,先找出即将超时的 timer,然后调用不同实现的 ngx_process_events(cycle, timer, flags)
然后 ngx_events_process_posted 处理 posted_accept_events 和 posted_events,并且在 posted_accept_events 后处理已经超时的链接
整个事件循环在 ngx_worker_process_cycle 里处理 cycle 和各种信号的标记
先抢锁在处理事件
连接 connection_t 里包含 http_connection 对象
设置为 nonblock 然后优先尝试读取一下,加快处理
超时处理时把 ev->timeout 标记,然后调用 ev->handle(ev) 处理,相关事件里会有处理超时的代码
事件结构体在初始化时通过 pool 来管理,而且使用了重用