- 1、本文档共37页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
互联网络程序设计第六章
第六章、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
您可能关注的文档
- 二年级上册1_4单元词语表.ppt
- 二年级体育理论复习题_姜忠生.ppt
- 二年级语文上册总复习和回答问题.ppt
- 二年级语文下册第1单元生字PPT.ppt
- 二数第十一周集体备课.ppt
- 二年级语文第4册.ppt
- 二月房价下跌悉尼幸免.pptx
- 二年级语文上第4单元复习课件.ppt
- 二月安全信息通报.ppt
- 二月份有机推断作业.ppt
- [++初中数学]+第2课时+从不同方向观察立体图形和立体图形的展开+++课件+人教版七年级数学上册.pptx
- [++初中数学]第4课时+方案选择问题(27页)+++课件+人教版数学七年级上册.pptx
- [++初中数学]+第2课时+角的平分线++课件+人教版数学七年级上册.pptx
- [++初中数学]+第2课时+方程的解及一元一次方程++课件++人教版数学七年级上册.pptx
- [++初中数学]成比例线段第2课时++等比性质课件+北师大版九年级数学上册.pptx
- [++初中数学]+第1课时+认识几何体课件+人教版数学七年级上册.pptx
- [++初中数学]第3课时+去括号解一元一次方程(23页)+++课件+教版数学七年级上册.pptx
- [++初中数学]二元一次方程组及其解法第3课时课件+沪科版数学七年级上册.pptx
- [++初中数学]几何图形初步+复习课+课件+人教版七年级数学上册.pptx
- [++初中数学]+二元一次方程组及其解法第1课时课件+沪科版数学七年级上册.pptx
文档评论(0)