HighTechTalks DotNet Forums  

Problem with C# asynchronous sockets

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss Problem with C# asynchronous sockets in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Kruz
 
Posts: n/a

Default Problem with C# asynchronous sockets - 10-01-2005 , 06:35 PM






Somewhere around 500 connections send callbacks stop in C# asynchronous
sockets. I'm counting how many BeginSend are issued and how many
EndSend are received, and somewhere around 500 connections send
callbacks stop coming even when the count for BeginSend shows that
there are pending sends in the system.

Is there are way to fix this problem?

Thanks in advance


Reply With Quote
  #2  
Old   
Kruz
 
Posts: n/a

Default Re: Problem with C# asynchronous sockets - 10-01-2005 , 10:48 PM






The server makes 108,752 calls (BeginSend calls) in within 25 seconds.


Reply With Quote
  #3  
Old   
Kruz
 
Posts: n/a

Default Re: Problem with C# asynchronous sockets - 10-02-2005 , 11:40 AM



Somewhere around 500 connections when calls (BeginSend calls) are
arround 108,752 and total bytes sent are around 9,496,399 bytes - send
callbacks (EndSend) stop coming in C# asynchronous sockets.

I'm counting how many BeginSend are issued and how many EndSend are
received, and somewhere around 500 connections send callbacks stop
coming even when the count for BeginSend shows that there are pending
sends in the system.

Here is the code:
---------------------------
private void SendData(OStateObject so, string sData)
{
byteData = Encoding.ASCII.GetBytes(sData);

try
{
so.socket.BeginSend(byteData, 0, byteData.Length, 0, new
AsyncCallback(SendCallback), so);
PendingSends = Interlocked.Increment(ref PendingSends);
}
catch(System.ObjectDisposedException)
{
}
catch (SocketException e)
{
DestoryStateObject(so);

}
catch (Exception e)
{
DestoryStateObject(so);
}
}

private void SendCallback(IAsyncResult ar)
{
OStateObject so = (OStateObject)ar.AsyncState;

try
{
MaxSendBytes += so.socket.EndSend(ar);
PendingSends = Interlocked.Decrement(ref PendingSends);
}
catch (SocketException e)
{
PendingSends = Interlocked.Decrement(ref PendingSends);
DestoryStateObject(so);
}
catch (Exception e)
{
PendingSends = Interlocked.Decrement(ref PendingSends);
DestoryStateObject(so);
}
}
---------------------------

Here is code from the timer which executes this code every 2 second.
---------------------------
if (ArrayListConnectedSockets.Count >= 500)
{
//"TBGSends" is a global variable to keep track of maximum number of
sends
string bgMsg = "TestData :ghghe ghghghghgh whrerhehrehreh
hthththththththht eherehherehhee ghghe ghghghghgh whrerhehrehreh
hthththththththht eherehherehhee\n";
OStateObject so;
for (int i=0; i<ArrayListConnectedSockets.Count || TBGSends <= 150000;
i++)
{
so = (OStateObject)ArrayListConnectedSockets[i];
SendData(so, bgMsg);
TBGSends++;
}

if (TBGSends >= 150000) TimerBG.Stop();
}
---------------------------

I'm restricting maximum number of connection to 1000 after reaching
this limit server shuts down every new connection.

Maximum a user can send 5 times within a second. If there are 1024
users connected to each other than the server would make 1047552 send
calls if all users send something to each other with in few seconds. 1
or 2 seconds delay doesn't matter but the server jams during the
communication.

Why the server is jamming and anyway to solve this problem in C#?


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.