Socket IOCP a waste?

Started by
6 comments, last by Karl G 20 years, 3 months ago
I''ve read up on a lot of IOCP stuff recently, and I think I have concluded that using it is a waste unless there is some big secret that I don''t know. All it seems to be doing is act as a mutex (mutual exclusion) object so that multiple threads can''t access the socket at the same time. The only difference I see is that with IOCP, you can pass little chunks of data everywhere (OVERLAPPED structures) for no particular reason. I mean compare this logic... [Mutex Thread] Wait for Mutex Do socket operation Release mutex Repeat [Overlapped Thread] Wait for overlapped completion Do socket operation (which automatically posts a completion o_O) Repeat There''s virtually no difference except that it''s a lot more confusing. So what''s up with this whole IOCP thing?
Advertisement
Check Chapter 6 of "Network Programming for Microsoft Windows"; there is a table with benchmarks in there. IOCP is the most performant method under very heavy loads. It is similar to overlapped IO with events, but the real difference is CPU usage. IOCP requires much less horsepower for the same amount of IO work because not all threads become active and thus there is less thread switching and cache trashing overhead.
Oh! Thanks AP! So what you''re saying basically is that when a thread is waiting for an IO operation to complete then it doesn''t ever go back into that thread until it does, preventing the overhead of switching between lots of threads. Did I get that right?
The OS ensures that the same threads gets awakened when the socket is active. If processing is fast, then there is only one IO thread running. For threaded overlapped IO (not IOCP) to work with large loads (1000s of sockets), then you would need to split the work amongst tons of threads because each thread cannot wait on more than 64 sockets at a time; and because such scheme rely on a round-robin allocation scheme, ALL threads are guaranteed to be awakened in turn, thus thrashing the CPU cache and incurring thread switching overhead (as many more threads will be active wrt IOCP). Again, IOCP doesn''t suffer from such limitations.
Definitely check out Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.

Kuphryn
thx kuphryn been looking for a book that covers IOCP
Does anyone know of any good online resources/tutorials that cover IOCP?
Check out MSDN.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_servrapp.asp

Kuphryn

This topic is closed to new replies.

Advertisement