- 1
- 0
- 约1.4万字
- 约 37页
- 2016-12-31 发布于北京
- 举报
第六章、I/O复用的服务器与客户端 I/O模型 select函数 IO复用客户端 IO复用服务器 select函数总结(poll与pselcet函数) 测试用例 1. I/O模型 I/O复用技术的引入 第3章,迭代服务器的低效率主要原因是串行执行 第4、5章,采用并行的思路来解决这个问题 从这一章开始,换一个思路 仔细分析迭代服务器模型 串行化还不是造成低效率主要原因 真正的原因是——阻塞 程序阻塞在read、accept等系统调用上,不能为其它客户端服务 串行的迭代服务器 网络操纵函数最终被抽象成文件的IO操作,着重对慢系统调用观察,会发现这些函数基本上分成两个阶段: 等待事件发生 程序与系统内核交互,获取发生的事件 根据这两个阶段的不同操作,可以分为五种IO模型 阻塞I/O 非阻塞I/O I/O复用(select、epoll、kqueue) 信号驱动I/O 异步I/O Blocking I/O Model The most prevalent I/O model 。By default, all sockets are blocking Nonblocking I/O Model When a socket is nonblocking, telling kernel: “ when an I/O operation that I request cannot be completed without putting the process th sleep, do not put the process to sleep”. It is called polling, waste of CPU time. I/O multiplexing Model When I/O multiplexing, we call select or poll and block in one of these two system call, instead of blocking in the actual I/O system call. Signal Driven I/O Model Telling the kernel to notify us with the SIGIO signal when the descriptor is ready. Advantage: process is not blocked while waiting for the datagram to arrive. Asynchronous I/O Model Asynchronous I/O tell the kernel to start the operation and to notify us when the entire operation is complete. Comparison of the I/O Model 五种IO模型回顾 同步与异步IO Posix定义这两个术语如下 同步I/O操作引起请求进程阻塞,知道I/O操作完成; 异步I/O操作不引起请求进程阻塞; IO的两个阶段都没有被阻塞,才能被称为异步IO 因此,阻塞I/O模型、非阻塞I/O模型、 I/O复用模型和信号驱动模型都是同步I/O模型;最后一种才是异步IO 实际编程中,这几种IO模型经常根据需要混用 首先要避免被阻塞,但是阻塞都不好? 在事件的检查点要阻塞 避免采用信号机制,主要原因是信号是异步的,将使程序变得很难编写。即使写成了这样的代码,也会由于引入防止异步干扰的代码,抵消掉信号带来的优势。 2. I/O Multiplexing What we need is the capability to tell the kernel that we want to be notified if one or more I/O conditions are ready (i.e., input is ready to be read, or the descriptor is capable of taking more output). This capability is called I/O multiplexing and is provided by the select and poll functions. Scenarios of I/O multiplexing When a client is handling multiple descriptors (normally interactive input and a network socket). If a TCP server h
您可能关注的文档
最近下载
- 租房合同范本,租房租房合同范本.docx VIP
- 2024-2025学年八年级数学上册:全等三角形的判定(ASA与AAS) 知识梳理与讲解.pdf VIP
- 2026-2030中国沼气产业深度解析及发展前景对策建议研究报告.docx
- 2023年广西南宁市中考数学一模试卷.pdf VIP
- 场地设计真题06-09年.pdf VIP
- 广东省2025年初中学业水平考试地理真题(含答案).pdf VIP
- 广东省高考:2025年-2023年《生物》考试真题与参考答案.pdf
- 2025年烟叶评级技能竞赛理论参考试题库-上(单选题汇总).docx
- 《心脑血管类》课件.pptx VIP
- 化工单机设备试车方案与操作流程.docx VIP
原创力文档

文档评论(0)