Click here to Skip to main content
15,889,216 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Click Events in .NET Pin
sarabjs15-Feb-05 13:03
sarabjs15-Feb-05 13:03 
GeneralRe: Click Events in .NET Pin
S. Senthil Kumar15-Feb-05 18:26
S. Senthil Kumar15-Feb-05 18:26 
GeneralRe: Click Events in .NET Pin
sarabjs22-Feb-05 10:22
sarabjs22-Feb-05 10:22 
GeneralDeserialization throws "No Top Object" exception. Pin
ganeshvijay14-Feb-05 20:55
ganeshvijay14-Feb-05 20:55 
Generalsuitability of .net for network servers Pin
kon_t14-Feb-05 8:25
kon_t14-Feb-05 8:25 
GeneralRe: suitability of .net for network servers Pin
Mike Dimmick15-Feb-05 2:20
Mike Dimmick15-Feb-05 2:20 
GeneralRe: suitability of .net for network servers Pin
kon_t16-Feb-05 15:42
kon_t16-Feb-05 15:42 
GeneralRe: suitability of .net for network servers Pin
Mike Dimmick17-Feb-05 2:57
Mike Dimmick17-Feb-05 2:57 
When you receive data on a connection where a thread is blocked on the socket, the kernel puts that thread on the runnable list. The kernel tries to balance the demand for CPU resources by switching between threads in a runnable state. At any given time there can only be one thread actually running on each logical CPU. The OS switches to a different thread if the running thread blocks, if the thread's quantum (time permitted to run) expires, or if another thread with a higher priority becomes runnable.

In the design where you have one thread per client, you can get a situation where multiple clients send packets simultaneously, unblocking all the threads for those clients. The OS then ends up switching between them. Context switches are not free - they take time. They also generally cause processor cache misses as each thread refers to data on its stack. A processor cache miss is not reflected in the performance counters, but it does take time.

This is time that could have been spent servicing requests.

Windows also offers asynchronous I/O. With asynchronous I/O, threads can be performing useful operations while the I/Os are pending. If the socket is not associated with a completion port[^], the I/O is associated with a particular thread.

I/O completion ports allow I/O to be associated with a pool of threads, so that any thread blocked on the completion port can handle a completed I/O. Windows performs some special tricks with threads associated with a completion port:
  • Threads are released from the completion port in reverse order of blocking - that is, the last thread to block is the first thread released. This helps prevent cache thrashing.
  • Windows only releases as many threads as can be handled with the CPUs in the system (or as many as specified, if the number of concurrent threads is specified when the completion port is created).
  • When a thread blocks on some other operation, Windows releases another thread from the pool waiting on the completion port, if there is one and there is work for it to do
In this way, Windows keeps all the CPUs busy.

The Framework does all the work behind the scenes to associate asynchronous I/O operations with a pool of worker threads, and manages the thread pool for you. You don't have to consider whether an asynchronous I/O completed synchronously (this can happen) as the Framework calls your callback function in either case.

This is rather different from select, which is a polling function. A transition from user to kernel mode is required for select to determine whether any data is waiting. It also has the problem that you can only specify a given maximum number of sockets in an fd_set (by defining the FD_SETSIZE macro).

Microsoft implements many of its network servers in this fashion - including IIS before version 6.0 (version 6.0 introduces the HTTP.SYS driver which performs much of the HTTP protocol in kernel mode to save kernel->user transitions).

Given the scale of your testing, you might not see much difference. I recently implemented a UDP-based client emulator in C#, using BeginSend/BeginReceive, to test against our application server. I found that it was using 20 threads to emulate 1000 clients with no think time. The server software, written in VB6 and mostly single-threaded, was unable to keep up with that rate of requests.

Stability. What an interesting concept. -- Chris Maunder
GeneralRe: suitability of .net for network servers Pin
kon_t17-Feb-05 11:46
kon_t17-Feb-05 11:46 
GeneralRe: suitability of .net for network servers Pin
Rei Miyasaka22-Feb-05 21:43
Rei Miyasaka22-Feb-05 21:43 
GeneralRe: suitability of .net for network servers Pin
Sebastian Schneider23-Feb-05 2:09
Sebastian Schneider23-Feb-05 2:09 
General.Net Control Printing Pin
khurram rasheed13-Feb-05 22:05
khurram rasheed13-Feb-05 22:05 
GeneralSummation of Hours in Dataset Pin
Vipul Mehta13-Feb-05 21:20
Vipul Mehta13-Feb-05 21:20 
GeneralRe: Summation of Hours in Dataset Pin
yasinPL17-Feb-05 14:09
yasinPL17-Feb-05 14:09 
GeneralCreate of PS Pin
sharathgowda13-Feb-05 18:10
sharathgowda13-Feb-05 18:10 
GeneralRe: Create of PS Pin
Mike Dimmick15-Feb-05 3:02
Mike Dimmick15-Feb-05 3:02 
GeneralGet Top 10 from a search engine Pin
Mohsen Saad12-Feb-05 7:38
Mohsen Saad12-Feb-05 7:38 
General.ARaw Packets Pin
Member 170239812-Feb-05 2:43
Member 170239812-Feb-05 2:43 
GeneralVisual Studio: DLL location for Debug Pin
Jerome RG12-Feb-05 0:51
Jerome RG12-Feb-05 0:51 
GeneralInformation Needed about MicroSoft Speech Server Pin
anand.narayan11-Feb-05 18:33
anand.narayan11-Feb-05 18:33 
GeneralCommunicating with a windows service from a forms application... Pin
obliojoe11-Feb-05 6:15
obliojoe11-Feb-05 6:15 
General.NET Forms: tab control flickering Pin
spoonspoon10-Feb-05 15:15
spoonspoon10-Feb-05 15:15 
GeneralTransactional hash tables Pin
Ray Cassick10-Feb-05 14:41
Ray Cassick10-Feb-05 14:41 
GeneralCInt(True) in C# Pin
goldoche10-Feb-05 8:54
goldoche10-Feb-05 8:54 
GeneralRe: CInt(True) in C# Pin
C# Genius10-Feb-05 9:06
C# Genius10-Feb-05 9:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.