File tree Expand file tree Collapse file tree 2 files changed +6
-10
lines changed Expand file tree Collapse file tree 2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change 6
6
7
7
版本一的框架如下图所示:
8
8
9
- <img src =" https://github.com/importcpp/httpServer/raw/master/file/serverarch1.png " alt =" v1 " style =" zoom : 45% ;" />
10
-
11
- ### Http version 2
9
+ ### ![ img] ( https://gitee.com/realgeorge/FIleForGithub/raw/master/file/serverarch1.png ) Http version 2
12
10
13
11
这里每次有新任务到达时,就将新任务转交给线程,然后把程序的控制权转交到Epoll上,但是当在高并发状态,连接数太高,就会有很多活动的事件fd, 这是频繁的转交线程也会造成很大的开销
14
12
25
23
26
24
此时的框架图如下图所示:
27
25
28
- < img src = " https://github .com/importcpp/httpServer /raw/master/file/serverarch2_0.png " alt = " v2 " style = " zoom : 45 % ; " />
26
+ ![ img] ( https://gitee .com/realgeorge/FIleForGithub /raw/master/file/serverarch2_0.png )
29
27
30
28
但是直接这样就 单个线程负责多个文件描述符 是不现实的,比如,A线程负责了 a3和a4两个文件描述符,如果主线程应该如何通知 A线程 去处理 a3和a4两个活动fd呢,这里虽然可以想办法实现(将发生活动事件的fd 作为数据写入eventfd,然后再唤醒线程),但是有没有更好的办法呢。
31
29
32
30
进一步的思考时 如何让单个线程彻头彻尾的负责多个文件描述符,彻尾很简单,负责文件描述符的close即可。彻头就是要去负责监视文件描述符的活动事件,也就是由主线程通知A线程,你应该负责a3 这个文件描述符,A线程中也应该创建epoll对象,将a3需要监听的事件加入进来。往后,可继续添加多个文件描述符。 其实这一步相当于对之前的思路做了一个调整,之前是想让主线程去监听所有事件,现在主线程只负责accept请求,然后将accept的对象的控制权转交给其余线程,至此,版本二的设想已经基本完成
33
31
34
32
版本二的基本框架如下图所示:
35
33
36
- < img src = " https://github .com/importcpp/httpServer /raw/master/file/serverarch2.png " alt = " v3 " style = " zoom : 80 % ; " />
34
+ ![ img] ( https://gitee .com/realgeorge/FIleForGithub /raw/master/file/serverarch2.png )
37
35
38
36
为了简化处理,接下来的版本V2_1 将完成单线程的http server
39
37
Original file line number Diff line number Diff line change 50
50
51
51
本服务器采用了事件循环 + 非阻塞IO的主题架构,通过事件驱动和事件回调来实现业务逻辑。事件循环用于做事件通知,如果有新的连接被Accept,则把新连接的socket对象的管理工作转交给其他线程。模型的整体架构如下图所示,模型的架构发展过程可见[ History] ( https://github.com/importcpp/WebServer/blob/master/History.md ) .
52
52
53
- < img src = " https://gitee.com/realgeorge/FIleForGithub/blob /master/file/serverarch2.png " alt = " v3 " style = " zoom : 80 % ; " />
53
+ ![ 模型架构 ] ( https://gitee.com/realgeorge/FIleForGithub/raw /master/file/serverarch2.png )
54
54
55
55
## Server Performance
56
56
71
71
72
72
* My Webserver 响应消息体为短字符串时测试结果
73
73
74
- ![ mine_qps ] ( https://github .com/importcpp/WebServer /raw/master/file/mine_qps.png )
74
+ ![ 自己服务器的QPS数据 ] ( https://gitee .com/realgeorge/FIleForGithub /raw/master/file/mine_qps.png )
75
75
76
76
* Muduo 响应消息体为短字符串时测试结果
77
77
78
- ![ muduo_qps] ( https://github.com/importcpp/WebServer/raw/master/file/muduo_qps.png )
79
-
80
-
78
+ ![ Muduo的QPS数据] ( https://gitee.com/realgeorge/FIleForGithub/raw/master/file/muduo_qps.png )
81
79
82
80
### Analysis
83
81
You can’t perform that action at this time.
0 commit comments