现在的位置: 首页 > Windows > 正文
解析Windows下IO调度模型:IOCP
2013年11月07日 Windows, Windows Server ⁄ 共 1391字 评论数 5 ⁄ 被围观 6,545 views+

1. 介绍

1.1 高并发服务器

(1)要求大规模的连接/会话可能同时进行

(2)列子:Web服务器, 邮件服务器

clip_image002

1.2 线程池架构

(1) 每个连接分配一个线程,将导致过多的线程。

(2) 线程消耗内存,比如堆栈等等。

(3) 操作系统创建和关闭线程,都将花费很多的时间在线程之间的切换

clip_image004

2. 线程模型

2.1 基于会话模型

(1) 每个线程服务于一个客户端,比如HTTP会话。

(2) 线程被用于状态跟踪和CPU调度。

(3) 活跃线程的数量等于并发客户端会话的数量

2.2 基于I/O模型

(1) 将状态跟踪从CPU调度中分离出来。

(2) 线程是所有同质,仅为I/O调用保持状态。

(3) 一个线程可以服务于不同的会话,在不同的时刻。

(4) 一个会话可以被服务,通过不同的线程,在不同的时刻。

(5) 因此,从一个线程不是专门对于一个会话,仅仅专门对于一个I/O请求处理。

3. 基于I/O的线程调度

clip_image006

3.1 并发限制

(1) 线程是和CPU绑定

最大活跃线程的个数 == CPU个数

(2) 线程是和I/O绑定

最大的工作线程个数 >= I/O并行个数

(3) 根据实验/基准设置

3.2 线程池大小

(1) 线程是和CPU绑定

等于并发限制数

(2) 线程是和I/O绑定

最大的工作线程个数 >= I/O并行个数

(3) 根据实验/基准设置

3.3 查询系统信息

typedef struct _SYSTEM_INFO {

union {

DWORD dwOemId;

struct {

WORD wProcessorArchitecture;

WORD wReserved;

};

};

DWORD dwPageSize;

LPVOID lpMinimumApplicationAddress;

LPVOID lpMaximumApplicationAddress;

DWORD_PTR dwActiveProcessorMask;

DWORD dwNumberOfProcessors;

DWORD dwProcessorType;

DWORD dwAllocationGranularity;

WORD wProcessorLevel;

WORD wProcessorRevision;

} SYSTEM_INFO;

4. Win32 完成端口

4.1 什么是IOCP

是一个Win32 机制,方便于带有控制并发的服务器的并发执行。

4.2 IOCP做什么

(1) 一个Win32 内核对象。

(2) 有用于Windows NT 和 后面的执行。

(3) 帮助维持重复使用的内存池。

删除线程创建/终结负担

(4) 分配线程,控制并发

最小化的线程上下文切换

(5) 优化线程调度

提高CPU和内存缓冲的命中率

4.3 基本步骤

clip_image008

4.4 创建IOCP端口和关联设备

4.5 IOCP内部结构

clip_image010

Note:

(1) 等待线程采用LIFO调度,减少了线程上下文的切换。只要I/O请求完成的够慢,使一个线程能够处理他们,系统就始终唤醒同一个线程。

(2) 当一个设备的异步I/O请求完成时,系统检查是否有关联了完成端口。如果是,那么系统就想该设备的完成端口I/O完成队列加入完成的I/O请求。

(3) IOCP是一个内核对象,它的值和I/O完成队列的地址指针是相同的。

4.6 I/O完成队列

(1) 当有一个异步I/O完成时,内核将检查是否该设备已经关联了某个IOCP。如果是,则一个完成数据包将被添加到完成队列中。

clip_image012

(2) 获取完成I/O请求

clip_image014

(3) 人工投递I/O请求包

clip_image016

5. 线程管理

5.1 线程状态类型

clip_image018

5.2 线程状态转换

clip_image020

6. 基于I/O的并行服务器

6.1 程序流程图

clip_image022

目前有 5 条留言 其中:访客:5 条, 博主:0 条

  1. Richard Ellenbogen : 2017年05月20日15:24:02  -49楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  2. Conslines.com : 2017年05月20日15:24:30  -48楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  3. Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  4. Lise Winicki : 2017年05月20日15:25:39  -46楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  5. Auto Connection : 2017年05月20日15:27:48  -45楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

给我留言

留言无头像?


×