Sunday, August 16, 2009

Network Programming with IOCP and Thread Pool - Intro

These days, I'm playing with network programming with IOCP and Thread Pool just for pure fun. :) After several days of reading MSDN, articles and writing experimental codes, I've realized that there are pretty big changes I need to catch up.

If you still use IOCP with GetQueuedCompletionStatus() and your custom threads (like me before), you might want to follow this series of postings I will update. I will provide sample code to clarify the right way to use them.

Also, I will benchmark techniques to each other so that hopefully I can give you some guidelines about When we need to use Which technique, or, at least, help you to avoid making the same mistakes I would make while I write this series.


First of all, let's see how many ways we can choose for using IOCP.

If we use custom threads to get I/O completion notification,

1. CreateIoCompletionPort() and GetQueuedCompletionStatus()

- Windows 2000 (Pro, Server) or later.

2. CreateIoCompletionPort() and GetQueuedCompletionStatusEx()
- Windows Vista and Server 2008 or later.



If we use Windows Thread Pool to get I/O completion notification,

3. BindIoCompletionCallback()

- Windows 2000 (Pro, Server) or later.

4. CreateThreadpoolIo(), StartThreadpoolIo() and etc

- Windows Vista and Server 2008 or later.

There also some APIs related to Thread Pool like QueueUserWorkItem(). Unfortunately but in a good way, Thread Pool system has been completely re-written for Windows Vista and we need to use those new and richer APIs to maximize our server performance.

If it's not confusing enough, I can tell you that there are also special socket functions which are Microsoft-specific extensions to the Windows Sockets specification. For example, ConnectEx(), AcceptEx() and etc. These functions are to fully utilize IOCP power for all IO operations including receive (read) and send (write).

Yes, it's gonna be a long journey but it must be fun! So excited! LOL


5 comments:

  1. Good luck on the journey! What are you planning to do with this tho?

    ReplyDelete
  2. To build High Perforamcne and Scalable 64 bits Server based on IOCP witn Thread Pool for Windows Server 2008 R2? :)

    ReplyDelete
  3. Good day! Do you know if they make any plugins to protect against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any tips? customwriting

    ReplyDelete
  4. This is a terrific site, could you be interested in doing an interview about just how you created it? If so e-mail me! customwriting

    ReplyDelete
  5. I truly admire everything you website in right here, highly informative and sensible. One issue, I am running Opera on Linux and some of the content are just a little wonky. I understand it’s not a popular, but it’s nonetheless something to watch out for. Just giving you a manages. customwriting

    ReplyDelete