|
Introduction to IOCP by yoonman
WhiningDog.NET
11/15/2002
Introduction
This is an introduction to a possible series of
articles that will explore various aspects of advanced windows programming
using threads and I/O Completion Ports (IOCP). The article assumes you
have some basic understanding of threads and winsock, however anyone with
some understanding of operating systems will likely benefit. This article
is based upon aspects of windows programming that I have picked up in
various books (cited at the end of the article) as well as professional
and academic experience. I am by far not the utmost expert in this field
and in many ways I hope to be learning as much as you are by tinkering
around with one of the most advanced and robust aspects of systems programming
in Microsoft Windows.
The Common Paradigm
I remember one of the first server applications
I made was a simple protocol server for a networking class in college.
I basically had one thread waiting and listening for requests, and then
upon every received request I would spawn a new thread that would handle
processing and responding. Each client thread would have to wait for the
I/O to return upon each communication exchange. This I/O model will work
well if there are only a few clients making infrequent requests. However
if you were to stress my application with hundreds of clients you would
soon realize a huge degradation in performance due to the immense amount
of context switching among the threads. I remember in operating systems
class we learned that context switching is an expensive process since
the CPU has to flush the processor pipleline before switching threads,
as well as take the time to save and load registers. A much more efficient
model would be to create a small amount of threads that finished jobs
as fast as possible with minimal interruptions. The threads should only
be switched out when the threads really did not need the processor time
anymore.
[Home]
[Next Page]
|