IO Model

本文講述IO model(IO模型)。

1.Basic concept

首先講述一些基本的概念。

1.1. Blocking call vs. Non-blocking call

什麼是Blocking call(阻塞調用) Non-blocking call(非阻塞調用)?

Blocking call cause the requesting process to be blocked until the call return.

Non-blocking call does not cause the requesting process to be blocked.

1.2. Synchronous IO vs. Asynchronous IO

1.2.1 首先什麼是Synchronous(同步)和Asynchronous(異步)?

Synchronous mean change at the same time and same step between 2 objectives
Asynchronous mean change not at the same time and same step between 2 objectives

同步異步是通用的概念,比如在TCP協議中已有同步的概念。
TCP 3 way handshake:
3 way handshake make client and server change at the same time, so segment for handshake call SYNC

1.2.2 接下來,我們討論什麼是Synchronous IO(同步IO)和Asynchronous IO (異步IO)?

Synchronous IO:
Process and kernel complete work at the same time
Asynchronous IO:
Process and kernel complete work not at the same time

For example:
Process read file A, kernel read file at the same time.
Process read files in the order of A,B,C, kernel also read files in the order of A,B,C, that is at the same step.

In practice, IO operation have request and result, in asynchronous IO, request and result is separate, there are 2 functions, one for request, one for result.

1.3. Multiplexing vs. multiple process/thread

Multiplexing is handle multiple request in one process/thread
Multiple process/thread is handle one request in one process/thread

Level Triggered(水平觸發)
Edge Triggered(邊緣觸發)

Multiplexing is a part of select, poll, epoll, kqueue, IOCP

1.4. Iterative vs. concurrent

Iterative: one after one
Concurrent: work at multiple threads

1.5. Polling triggers notification vs. call back notification

Select, poll, epoll, IOCP is polling triggers notification
Signal is call back notification

1.6. IO Ready Notification vs. IO Complete Notification

IO READY Notification: IO is ready, such as readable, writable
Completed IO Request Notification: IO request is completed

2.各操作系統的支持

上面介紹了一些基本概念,這些基本概念中有一些是操作系統的基本機制,比如IO Ready Notification vs. IO Complete Notification兩種機制。下面介紹一下各操作系統的一些IO model要用到的一些機制。

2.1 Linux IO Ready Notification

2.1.1 IO file descriptor Notification

This is not independent mechanism, it is a part of select, poll, epoll mechanism.

2.1.2 Signal Notification (SIGIO)

2.2 Linux Completed IO Request Notification

2.2.1 Linux Native AIO

A completed IO Request Notification mechanism is built in Linux Native AIO

2.3 Windows Completed IO Request Notification

2.3.1. IO Completion Port

A completed IO Request Notification mechanism is built in IO Completion Port

2.3.2. windows Device kernel object

2.3.3. windows event

2.3.4. windows alertable IO

3. Target of IO Model

我們研究IO模型的目的是最大化利用CPU,要最大化利用CPU就要去除無用的操作,那什麼是無用的操作那,blocking和線程的CPU上線文切換都是無用的操作。

Maximize CPU utilization -> no useless operation -> no block, no context switch

Make thread keeping working and busy

4. IO Model

我將IO Model總體上分爲三類:

  • 1.All in one call I/O Model category
  • 2.IO Ready Notification I/O Model category
  • 3.Completed IO Request Notification I/O Model category

這裏寫圖片描述

Blocking and Non-blocking in Asynchronous 沒有太大的意義

3.1. Synchronous blocking Model category
3.2. Synchronous non-blocking Model category
3.3. IO Ready Model category
3.4. Asynchronous Model (IO complete Model) category

4. Common Synchronous blocking Model Category (3 models)

各種操作系統對這類IO model都有支持,而且採用的形式都一致,因爲這總模型基於blocking socket api,所以稱這類模型是common。

在這個類別下有幾種不同的實現,主要的區別在於使用Iterative還是使用Concurrent。

4.1. Synchronous Blocking Iterative Model

4.2. Synchronous Blocking Concurrent Model

4.2.1. Synchronous Blocking Request Separation Model

4.2.2. Synchronous Blocking Read/Write Separation Model

5. Common Synchronous Non-blocking Model Category (1 models)

各種操作系統對這類IO model也都有支持,而且採用的形式都一致,因爲這總模型基於non-blocking socket api,所以稱這類模型是common的。

8. Linux IO Ready Notification I/O Model Category (4 Models)

8.1. SIGIO
8.1.1. SIGIO – Blocking Model

8.1.2. SIGIO – Non-Blocking Model

8.2. Select model
8.2.1. Select-Blocking Model

8.2.2. Select-Non-blocking Model
8.3. Poll Model
8.4. Epoll Model

9. Linux Completed IO Request Notification I/O Model Category (4 Models)**

9.1. linux native aio Model (blocking)

9.2. Linux native aio with epoll Model (blocking)
9.3. Epoll with multi-thread Model
9.4. Linux native aio, Epoll, multi-thread Model

11. Windows IO Ready Notification I/O Model

11.1. Windows WSAAsyncSelect Model
11.2. Windows WSAEventSelect Model

12. Windows Completed IO Request Notification I/O Model

12.1. Only Completed IO Request Notification Model
12.1.1. windows Device kernel object Model (overlap IO) (Asynchronous blocking)
12.1.2. windows event Model (overlap IO) (Asynchronous blocking)
12.1.3. Completion Routine Model (overlap IO) (windows alertable IO) (Asynchronous blocking)
12.2. Using Completed IO Request Notification and Multiplexing Model
12.2.1. Windows IO completion port Model (Asynchronous Non-blocking)

13. Solaris Completed IO Request Notification I/O Model

13.1. Event completion Model

14. glibc Completed IO Request Notification

14.1. Signal
Signal in Posix aio
14.2. Callback
Callback in Posix aio

15. Glibc Completed IO Request Notification I/O Model

15.1. Posix aio (signal, call) Model (Asynchronous Non-blocking)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章