際際滷

際際滷Share a Scribd company logo
Windows Registered I/O (RIO)
Introduction & Performance
Seungmo Koo (@sm9kr)
覩手記 殊 蟆 覯  覈
Agenda
 IOCP: I/O Completion Port
 RIO: Registered I/O Network Extensions
 焔 螳
 蟆磯
 Source Code Sample
IOCP 螳
 る   蟆
 Proactor 覦 螻焔 I/O Notification Model
 觜蠍 I/O 讌

 Windows OS螳 讌  磯 襷 螻
 context-switching 譴企 螻

 Overlapped I/O 讌
 貉る螻  覯 螻旧 (memory page-locking)

 蠏碁殊 覿蟲螻,
  I/O operation襷 覯   page-lock/unlock
 轟 覃覈襴  Pin/Unpin 襷 CPU cycle蟲
 蠏碁 RECV襯 posting  , page-locking 狩 CPU cycle
譴願鍵  zero-byte recv 蠎殊襯 伎

  I/O operation襷 ろ貊 語
 覈-貉る覈  覦
IOCP 蟲譟
 蠍磯蓋 豌襴 襴
 I/O initiation  I/O processing  I/O completion

 I/O Initiation
User Virtual Address
Space

WSARecv(socket, buffer)

App
Physical Memory

User
Kernel

Winsock
I/O Manager
WS/Transport

I/O Request

NIC
IOCP 蟲譟
 I/O Processing
User Virtual Address
Space

WSARecv(socket, buffer)
App
Physical Memory

User
Kernel

Winsock
I/O Manager
WS/Transport

I/O Request

NIC

DMA

Scatter/gather I/O
襯 讌 NIC
 User覯朱 覦
襦 DMA
IOCP 蟲譟
 I/O Completion
User Virtual Address
Space

WSARecv(socket, buffer)
App

GQCS()
Physical Memory

User
Kernel

Winsock
unlock

I/O Manager
WS/Transport

I/O Request

NIC
RIO 螳
 Lower latency and jitter襯 
 讌一 豕 覦 讌 (?)  (豸♀レ)
 () 覿覩語 譯殊 覲 覦: 豐 5覦焔 一危 
 () Database 覯 UDP ろ碁Μ覦 螳 螻褐 豐 
豌襴 襦 豕螻 焔レ 觸
 豌    豌襴 襴 (by MS)

 轟
 I/O  螻 蠍一 覯朱ゼ 焔 螳
 覓朱Μ 覃覈襴  覯朱ゼ  pin企螻 郁鍵 覓語 襷る
I/O襷 page-lock/unlock 
 覃覈襴 螻 CPU螳 Trade-off
 I/O 覯 碁る れ I/O 覿襴 I/O 觜 螳 

 RIO 貉る 貅 覯朱 覩 
 SO_SNDBUF, SO_RCVBUF
RIO Buffer 焔
 RIO  螻 覯 焔 螻殊
 RB: User螻 Kernel 螻旧 伎襦 PIN
 RIODeregisterBuffer蠍 蟾讌 螻 locking
User Virtual Address
Space

App

User
Kernel

RIORegisterBuffer(buf,size)

RB ID

Physical Memory

Winsock
lock

I/O Manager

WS/Transport

RB

NIC
RIO RQ/CQ 焔
 RIO  螻 蠍一 RQ 覦 CQ 焔
 覈 I/O豌 RequestQueue (RQ)襯 牛 企伎
 I/O 襭  旧 CompletionQueue (CQ)襯 牛 豌襴

App

RIOCreateCQ(size)
RIOCreateRQ(sock, CQ)

Winsock

RQ
CQ

User
Kernel

I/O Manager

WS/Transport
NIC
RIO 蟲譟
 I/O 豌襴 螻殊
 DequeueCompletion 覲旧螳 I/O襭 旧螳 
 覯 螻殊朱 CQ    螳 I/O 豌襴
App

RIOReceive(RQ, RBID)

Winsock
User
Kernel

RIODequeueCompletion(CQ)
RIONotify(CQ)

RQ

R

C
CQ

I/O Manager

WS/Transport

R
NIC

C
焔 螳
 MS 焔ロ螳
 RIO  Latency螳 15~30% 螳 譴企れり 
 RIO  Throughput 豕 2覦 り  (Datagrams/s)

 讌 企蓋 焔ロ螳 (IOCP vs RIO)
  ル
 企殊伎誤: i7-4770k, 16GB RAM, 1Gbps LAN, Windows 8
 覯: Mac-mini server 2012 late, Windows Server 2012

 1024 byte UDP  5豌襷螳  ろ
 IOCP RIO 蟆曙 覈 1Gbps  full襦 
 蠏碁る慨  蟆曙 覈 throughput螻 UDP 襯 觜
損 讀, 覩  蟆郁骸 覈視 (10Gbps  谿願 襷  ?)

 蠏碁, 螳 
 RIO螳 CPU襯  2覦 
 RIO context-switches/sec螳 6覦 螳
CPU Usage

IOCP

 20%

RIO
 10%
System Calls Per Second

IOCP

217,991,452

RIO
16,268,070
Context Switches Per Second

IOCP

74,182,111

RIO
11,926,964
蟆磯?
 RIO螳 焔レ ろ 譬
 Throughput: MS 覃 2覦 螳 譬讌り 
 CPU 襯 : 讌 焔 ろ 蟆郁骸 燕 譬
 Context-switching 覦 System call   

 蠏碁磯謂
 蟲褐 螻焔 蟆 覯朱 RIO蟾讌  螳 蟾?
  譬讌 襾語 焔,  覲旧″ 貊 覦覯, MS  譬, 
 Gigabit ろ語  throughput 蟆曙一
 IOCP 訖襷  Linux EPOLL螻朱 覲 谿 

 蟆 覯 Gigabit 伎   蟆曙 れ 螳企?
 碁曙 襷 蟆覯手 企瓦 300~400Mbps 
     蟆曙, CPU 襯 谿企 伎
Sample Code
 企 襦   貊螳 伎 讌 蟲
 MSDN 覓語 譟一姶 襦  讌 
 襷 曙

 豕   貊襷 れ 
 覯蠏語  豈 

 Source Code: RIO Echo Server
 TCP, RIO only
 https://github.com/zeliard/RIOTcpServer

 UDP, IOCP+RIO
 https://github.com/zeliard/RIOEchoServer
[Update] RIO  譯殊 
 RIO 企欧 旧
 IOCP   Event襯 伎 I/O 企欧 旧襯 覦  
讌襷 豢豌讌   ろ 貊 螳 企 焔 
  焔 螳 IOCP襯 企欧 旧 覈碁  蟆曙一
 企蟆 企 貉ろ れ豺 6覦 螳 讌襷,
 IOCP 螳 企欧 旧   RIODequeueCompletion襷 伎
蟆 豕螻 焔レ . , Sleep or WaitableTimer煙 伎 CPU 
襯 豢蟆  (TCP覯 れ 谿瑚)

 Request/Completion Queue
 Thread-safe讌 蠍 覓語 蟲 り螳 
 () 語 覲襦 轟  thread 

 CQ thread覲襦, RQ socket覲襦 襷 蟆 蟲譟 覦 覃伎
 譬

 NUMA ル RIO
 RIO螳 user-level communication 覦 蟯螻襦  CPU 貊企ゼ
螻螻襭  螻螳
谿瑚 襭
 Tech to Develop Low Latency Apps, Build 2011.
 http://channel9.msdn.com/Events/Build/BUILD2011/SAC593T/player?w=960&h=544

 The Server Framework
 http://www.serverframework.com/asynchronousevents/rio/

More Related Content

Windows Registered I/O (RIO) vs IOCP

  • 1. Windows Registered I/O (RIO) Introduction & Performance Seungmo Koo (@sm9kr) 覩手記 殊 蟆 覯 覈
  • 2. Agenda IOCP: I/O Completion Port RIO: Registered I/O Network Extensions 焔 螳 蟆磯 Source Code Sample
  • 3. IOCP 螳 る 蟆 Proactor 覦 螻焔 I/O Notification Model 觜蠍 I/O 讌 Windows OS螳 讌 磯 襷 螻 context-switching 譴企 螻 Overlapped I/O 讌 貉る螻 覯 螻旧 (memory page-locking) 蠏碁殊 覿蟲螻, I/O operation襷 覯 page-lock/unlock 轟 覃覈襴 Pin/Unpin 襷 CPU cycle蟲 蠏碁 RECV襯 posting , page-locking 狩 CPU cycle 譴願鍵 zero-byte recv 蠎殊襯 伎 I/O operation襷 ろ貊 語 覈-貉る覈 覦
  • 4. IOCP 蟲譟 蠍磯蓋 豌襴 襴 I/O initiation I/O processing I/O completion I/O Initiation User Virtual Address Space WSARecv(socket, buffer) App Physical Memory User Kernel Winsock I/O Manager WS/Transport I/O Request NIC
  • 5. IOCP 蟲譟 I/O Processing User Virtual Address Space WSARecv(socket, buffer) App Physical Memory User Kernel Winsock I/O Manager WS/Transport I/O Request NIC DMA Scatter/gather I/O 襯 讌 NIC User覯朱 覦 襦 DMA
  • 6. IOCP 蟲譟 I/O Completion User Virtual Address Space WSARecv(socket, buffer) App GQCS() Physical Memory User Kernel Winsock unlock I/O Manager WS/Transport I/O Request NIC
  • 7. RIO 螳 Lower latency and jitter襯 讌一 豕 覦 讌 (?) (豸♀レ) () 覿覩語 譯殊 覲 覦: 豐 5覦焔 一危 () Database 覯 UDP ろ碁Μ覦 螳 螻褐 豐 豌襴 襦 豕螻 焔レ 觸 豌 豌襴 襴 (by MS) 轟 I/O 螻 蠍一 覯朱ゼ 焔 螳 覓朱Μ 覃覈襴 覯朱ゼ pin企螻 郁鍵 覓語 襷る I/O襷 page-lock/unlock 覃覈襴 螻 CPU螳 Trade-off I/O 覯 碁る れ I/O 覿襴 I/O 觜 螳 RIO 貉る 貅 覯朱 覩 SO_SNDBUF, SO_RCVBUF
  • 8. RIO Buffer 焔 RIO 螻 覯 焔 螻殊 RB: User螻 Kernel 螻旧 伎襦 PIN RIODeregisterBuffer蠍 蟾讌 螻 locking User Virtual Address Space App User Kernel RIORegisterBuffer(buf,size) RB ID Physical Memory Winsock lock I/O Manager WS/Transport RB NIC
  • 9. RIO RQ/CQ 焔 RIO 螻 蠍一 RQ 覦 CQ 焔 覈 I/O豌 RequestQueue (RQ)襯 牛 企伎 I/O 襭 旧 CompletionQueue (CQ)襯 牛 豌襴 App RIOCreateCQ(size) RIOCreateRQ(sock, CQ) Winsock RQ CQ User Kernel I/O Manager WS/Transport NIC
  • 10. RIO 蟲譟 I/O 豌襴 螻殊 DequeueCompletion 覲旧螳 I/O襭 旧螳 覯 螻殊朱 CQ 螳 I/O 豌襴 App RIOReceive(RQ, RBID) Winsock User Kernel RIODequeueCompletion(CQ) RIONotify(CQ) RQ R C CQ I/O Manager WS/Transport R NIC C
  • 11. 焔 螳 MS 焔ロ螳 RIO Latency螳 15~30% 螳 譴企れり RIO Throughput 豕 2覦 り (Datagrams/s) 讌 企蓋 焔ロ螳 (IOCP vs RIO) ル 企殊伎誤: i7-4770k, 16GB RAM, 1Gbps LAN, Windows 8 覯: Mac-mini server 2012 late, Windows Server 2012 1024 byte UDP 5豌襷螳 ろ IOCP RIO 蟆曙 覈 1Gbps full襦 蠏碁る慨 蟆曙 覈 throughput螻 UDP 襯 觜 損 讀, 覩 蟆郁骸 覈視 (10Gbps 谿願 襷 ?) 蠏碁, 螳 RIO螳 CPU襯 2覦 RIO context-switches/sec螳 6覦 螳
  • 13. System Calls Per Second IOCP 217,991,452 RIO 16,268,070
  • 14. Context Switches Per Second IOCP 74,182,111 RIO 11,926,964
  • 15. 蟆磯? RIO螳 焔レ ろ 譬 Throughput: MS 覃 2覦 螳 譬讌り CPU 襯 : 讌 焔 ろ 蟆郁骸 燕 譬 Context-switching 覦 System call 蠏碁磯謂 蟲褐 螻焔 蟆 覯朱 RIO蟾讌 螳 蟾? 譬讌 襾語 焔, 覲旧″ 貊 覦覯, MS 譬, Gigabit ろ語 throughput 蟆曙一 IOCP 訖襷 Linux EPOLL螻朱 覲 谿 蟆 覯 Gigabit 伎 蟆曙 れ 螳企? 碁曙 襷 蟆覯手 企瓦 300~400Mbps 蟆曙, CPU 襯 谿企 伎
  • 16. Sample Code 企 襦 貊螳 伎 讌 蟲 MSDN 覓語 譟一姶 襦 讌 襷 曙 豕 貊襷 れ 覯蠏語 豈 Source Code: RIO Echo Server TCP, RIO only https://github.com/zeliard/RIOTcpServer UDP, IOCP+RIO https://github.com/zeliard/RIOEchoServer
  • 17. [Update] RIO 譯殊 RIO 企欧 旧 IOCP Event襯 伎 I/O 企欧 旧襯 覦 讌襷 豢豌讌 ろ 貊 螳 企 焔 焔 螳 IOCP襯 企欧 旧 覈碁 蟆曙一 企蟆 企 貉ろ れ豺 6覦 螳 讌襷, IOCP 螳 企欧 旧 RIODequeueCompletion襷 伎 蟆 豕螻 焔レ . , Sleep or WaitableTimer煙 伎 CPU 襯 豢蟆 (TCP覯 れ 谿瑚) Request/Completion Queue Thread-safe讌 蠍 覓語 蟲 り螳 () 語 覲襦 轟 thread CQ thread覲襦, RQ socket覲襦 襷 蟆 蟲譟 覦 覃伎 譬 NUMA ル RIO RIO螳 user-level communication 覦 蟯螻襦 CPU 貊企ゼ 螻螻襭 螻螳
  • 18. 谿瑚 襭 Tech to Develop Low Latency Apps, Build 2011. http://channel9.msdn.com/Events/Build/BUILD2011/SAC593T/player?w=960&h=544 The Server Framework http://www.serverframework.com/asynchronousevents/rio/