IOCP in a custom thread pool

I am currently searching the web for a custom flow implementation. I found an implementation that uses IOCP. I'm wondering what is the use of them? They provide job theft or something, I could actually find the answer ...

+1


source to share


3 answers


IOCP = "I / O Completion Port". It is a kernel object built into the Windows OS that gives you a smart way to manage multithreaded asynchronous IO.

In very simplified (and slightly more simplistic) terms, you tell the IOCP about the IO job you want to do. It will execute them asynchronously and maintain a queue of the results of each of these jobs. Your call to inform the IOCP of the job returns immediately (it doesn't block while the IO is in progress). You are returned an object that is conceptually similar to the .NET IAsyncResult ... it allows you to block if you choose, or you can provide a callback, or you can poll periodically to see if the job has completed.



The IOCP uses a thread pool to perform these jobs. The thread pool tries to limit the number of threads to or less processors (this is configurable, but the goal and default is to limit the number of processors). However, the IOCP makes a provision that sometimes tasks on these threads can block. Asycn IO tasks won't block, but you could give it another task. So you can assign another number to the IOCP ... this is the number of threads above the "normal maximum" that the IOCP is allowed to raise because one of the other threads is blocked. The goal is to have up to the "normal maximum" threads actually doing something (ie not blocking). If this happens, then for a while the IOCP will use more threads than the normal max,but it will refuse to create any new threads until it can return to "normal maximum".

This is a short summary, conceptual only, and, as I said, oversimplified. But that should give you a general idea. Jeffrey Richter's books on Windows describe this in detail (but those books are out of print now). You can find these books and they are actually more expensive than they used to be. I think "Advanced Windows" is the title you want, but there may have been an updated version of the book with a different title.

+7


source


The best advantage of using IOCP for a thread pool is that it is in control of its threads and if for any reason a thread blocks for more than 100ms (including a page failure, a block call, etc.), it releases another thread that was waiting due to the reached concurrency limit. I don't know the internal implementation, but I don't think it uses the work steal queue.



0


source


You can use the IOCP implementation if you plan on using Windows I / O functionality from your worker threads. The IO function can be read / written to disk or network.

Check out the Push Framework http://www.pushframework.com to see how IOCP is used to implement a real time server.

-1


source







All Articles