Context switches on receiving data over SOCKET

How do I keep the context switches to a minimum level? is there a technique or guideline available? I am seeing about 7000 to 8000 system context switches per second. Is that normal or is there something that can be done to reduce that number? Please let me know.

Thank you, Srini.

[297 byte] By [Srini_Katta] at [2008-2-15]
# 1

I thought I should add more detail.

I have a VC++ 2005 application. I am using SOCKET and socket send recv etc. I’m not using any IOCP etc. which helps in scalability. I am running this application on Windows 2003 Standard Edition on a DELL server with 100Mbps network interface reading the data over TCP stream. When I receive about 6 mega bytes bytes of data per second on the TCP stream socket , I see lot of Context Switches per second, about 8000 to 9000. And these switches, I believe, are driving the CPU usage to higher. I am trying to figure out a way to minimize the context switches and thereby reduce the CPU usage. Your help is appreciated.

Thank you, Srini

Srini_Katta at 2007-9-28 > top of Msdn Tech,Windows Networking Development,Peer-to-Peer Networking...
# 2

This is the Peer-to-Peer Networking forum. You are asking for a diagnosis of Winsock behavior so perhaps a better place to ask this question is the Microsoft Networking newsgroup (which the Winsock team reads) -- http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.win32.programmer.networks.

Without a better understanding of your program's design it is difficult to be certain what is causing the seemingly excessive context switches. I find it bizzare that you mention that you are avoiding IO completion ports (a.k.a. IOCP, http://msdn.microsoft.com/msdnmag/issues/1000/Winsock/, http://msdn2.microsoft.com/en-us/library/aa365198.aspx) under the belief that not using IO completion ports somehow improves scalability. Perhaps I have misunderstood you but IO completion ports minimize the number of threads you need to create to send and receive data and also help you maximize your use of a worker thread's quantum (thus reducing context switches). If you are in fact not using IO completion ports I urge you to learn more about them and revisit this decision.

People on the newsgroup I mentioned above should be able to help you get to the root of this issue.

-Eliot

EliotFlannery-MSFT at 2007-9-28 > top of Msdn Tech,Windows Networking Development,Peer-to-Peer Networking...