Click here to Skip to main content
16,016,814 members
Home / Discussions / C#
   

C#

 
AnswerRe: how do i make the value in text box permanent Pin
Guinness4Strength9-Jun-04 5:07
Guinness4Strength9-Jun-04 5:07 
GeneralRe: how do i make the value in text box permanent Pin
Heath Stewart9-Jun-04 5:59
protectorHeath Stewart9-Jun-04 5:59 
GeneralRe: how do i make the value in text box permanent Pin
surgeproof9-Jun-04 10:23
surgeproof9-Jun-04 10:23 
GeneralRe: how do i make the value in text box permanent Pin
Heath Stewart9-Jun-04 10:30
protectorHeath Stewart9-Jun-04 10:30 
AnswerRe: how do i make the value in text box permanent Pin
Heath Stewart9-Jun-04 6:04
protectorHeath Stewart9-Jun-04 6:04 
GeneralConversion of Unmanaged COM in VC++ to Managed VC++ or C# Pin
imran1899-Jun-04 2:49
imran1899-Jun-04 2:49 
GeneralRe: Conversion of Unmanaged COM in VC++ to Managed VC++ or C# Pin
Heath Stewart9-Jun-04 5:53
protectorHeath Stewart9-Jun-04 5:53 
GeneralIO completion ports and unexpected performance. Pin
Angelos Petropoulos9-Jun-04 2:36
Angelos Petropoulos9-Jun-04 2:36 
Hi,

I've been lookin at using IO Completion Ports (through Socket.BeginXxx) within my network application (instead of using a thread for each client connection), but my findings are discouraging.

I was under the impression that IO Completion Ports improve performance and are a scalable solution to client/server connections. For this, I was expecting any benchmarks between using IO Completion Ports and using a thread for each client connection to be in favour ot IO Completion Ports. My tests however, indicate otherwise.

My tests are very simple, client sends a message and server receives it. No other action takes place, it is as simple as that. Here is the interesting part of the code:

Server

private void BytesReceived(IAsyncResult ar) {
   SocketAndBuffer socketAndBuffer = (SocketAndBuffer) ar.AsyncState;
   int noOfBytesReceived = socketAndBuffer.Socket.EndReceive(ar);
   if (noOfBytesReceived != 0) {
      socketAndBuffer.Socket.BeginReceive(socketAndBuffer.Buffer, 0,
           socketAndBuffer.Buffer.Length, SocketFlags.None, new AsyncCallback
           (this.BytesReceived), socketAndBuffer);
   }
}


Client

while (true) {
   socket.Send(bytesToSend, 0, bytesToSend.Length, SocketFlags.None);
   Thread.Sleep(10);
}


I run two variations of the test, one with the code as it appears above and the other (more brute force) with the Thread.Sleep(10) commented out. Below are the results:

10ms wait between sends, using completion ports, 40 connections
----------------------------------------------------------------
Processor Queue Length: 42.700 average, 44.000 max
Processor Time: 0.501 average, 5.000 max
Context Switches/sec: 16394.070 average, 16486.271 max

10ms wait between sends, using threads, 40 connections
------------------------------------------------------
Processor Queue Length: 42.817 average, 46.000 max
Processor Time: 0.167 average, 1.000 max
Context Switches/sec: 16343.139 average, 16475.683 max

No wait between sends, using completion ports, 1 connection
-----------------------------------------------------------
Processor Queue Length: 6.098 average, 9.000 max
Processor Time: 100 average, 100 max
Context Switches/sec: 13842.128 average, 14126.729 max

No wait between sends, using completion ports, 10 connections
-------------------------------------------------------------
Processor Queue Length: 6.475 average, 11.000 max
Processor Time: 100 average, 100 max
Context Switches/Sec: 48305.052 average, 49553.108 max

No wait between sends, using threads, 1 connection
--------------------------------------------------
Processor Queue Length: 6.525 average, 11.000 max
Processor Time: 100 average, 100 max
Context Switches/Sec: 52214.525 average, 53155.988 max

No wait between sends, using threads, 10 connection
---------------------------------------------------
couldn't gather statistics, CPU was getting hammered


In the case of 10ms wait between sends and 40 connections, using
threads instead of completion ports results in 3 times less cpu util
on average, 5 times less peak cpu util and on par context switches and
processor queue length.

In the case of no wait between sends and 1 connection, using threads
results in an 8% more context-switches and everything else on par.

It was not possible to gather statistics for 10 connections using
threads and no waiting between sends, but I think that's because all
the threads run at a priority level of Normal, hogging the CPU whilst
the completion ports have a threshold. No matter how many connections
I created to the server using completion ports, cpu util would remain
the same, it just had more requests queuing up.

What are your thoughts on this?

Thank you in advance
Angelos Petropoulos
GeneralRe: IO completion ports and unexpected performance. Pin
scadaguy9-Jun-04 16:34
scadaguy9-Jun-04 16:34 
GeneralRe: IO completion ports and unexpected performance. Pin
Angelos Petropoulos10-Jun-04 1:48
Angelos Petropoulos10-Jun-04 1:48 
GeneralRe: IO completion ports and unexpected performance. Pin
scadaguy10-Jun-04 2:27
scadaguy10-Jun-04 2:27 
GeneralRe: IO completion ports and unexpected performance. Pin
Angelos Petropoulos10-Jun-04 13:25
Angelos Petropoulos10-Jun-04 13:25 
GeneralRe: IO completion ports and unexpected performance. Pin
scadaguy11-Jun-04 3:06
scadaguy11-Jun-04 3:06 
GeneralRe: IO completion ports and unexpected performance. Pin
Angelos Petropoulos11-Jun-04 3:27
Angelos Petropoulos11-Jun-04 3:27 
GeneralRe: IO completion ports and unexpected performance. Pin
k.mohan kumar28-Jan-09 20:11
k.mohan kumar28-Jan-09 20:11 
GeneralRe: IO completion ports and unexpected performance. Pin
Angelos Petropoulos11-Jun-04 1:44
Angelos Petropoulos11-Jun-04 1:44 
GeneralRe: IO completion ports and unexpected performance. Pin
scadaguy11-Jun-04 3:24
scadaguy11-Jun-04 3:24 
GeneralRe: IO completion ports and unexpected performance. Pin
Angelos Petropoulos11-Jun-04 3:37
Angelos Petropoulos11-Jun-04 3:37 
GeneralRe: IO completion ports and unexpected performance. Pin
Angelos Petropoulos11-Jun-04 5:29
Angelos Petropoulos11-Jun-04 5:29 
GeneralRe: IO completion ports and unexpected performance. Pin
Colby James Smith1-Sep-04 10:06
Colby James Smith1-Sep-04 10:06 
Questionwhat is the differcence between close and dispose with Process instance? Pin
fu09-Jun-04 2:36
fu09-Jun-04 2:36 
AnswerRe: what is the differcence between close and dispose with Process instance? Pin
Heath Stewart9-Jun-04 2:54
protectorHeath Stewart9-Jun-04 2:54 
GeneralRe: what is the differcence between close and dispose with Process instance? Pin
fu09-Jun-04 16:52
fu09-Jun-04 16:52 
GeneralRe: what is the differcence between close and dispose with Process instance? Pin
Heath Stewart10-Jun-04 3:09
protectorHeath Stewart10-Jun-04 3:09 
AnswerRe: what is the differcence between close and dispose with Process instance? Pin
Alvaro Mendez9-Jun-04 8:45
Alvaro Mendez9-Jun-04 8:45 

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.